I'm trying to run a OSX command which is plutil to convert certain plist to json format. The command that I use in terminal is
plutil -convert json -o - '/Users/chris/project/temp tutoral/project.plist'
This command with path name having white spacing works fine in my terminal with the apostrophe (") sign covering the path name but the problem is with running this command in java's Runtime.getRuntime().exec(cmdStr)
below is the code that i wrote
public static void main(String args[]){
LinkedList<String> output = new LinkedList<String>();
String cmdStr = "plutil -convert json -o - /Users/chris/project/temp tutoral/project.plist";
//String cmdStr = " plutil -convert json -o - '/Users/chris/project/temp tutoral/project.plist'";
//String [] cmdStr ={ "plutil -convert json -o - ", ""Users/chris/project/temp tutoral/project.plist""};
Process p;
try {
p = Runtime.getRuntime().exec(cmdStr);
BufferedReader reader = new BufferedReader(new InputStreamReader(p.getInputStream()));
String line = "";
while ((line = reader.readLine()) != null) {
output.add(line);
System.out.println(line);
}
} catch (Exception e) {
e.printStackTrace();
}
}
If i run this code it would give me an error of
'Users/chris/project/temp: file does not exist or is not readable or is not a regular file (Error Domain=NSCocoaErrorDomain Code=260 "The file “temp” couldn’t be opened because there is no such file." UserInfo=0x7fd6b1c01510 {NSFilePath='Users/chris/project/temp, NSUnderlyingError=0x7fd6b1c01280 "The operation couldn’t be completed. No such file or directory"})
tutoral/project.plist': file does not exist or is not readable or is not a regular file (Error Domain=NSCocoaErrorDomain Code=260 "The file “project.plist” couldn’t be opened because there is no such file." UserInfo=0x7fd6b1d6dd00 {NSFilePath=tutoral/project.plist', NSUnderlyingError=0x7fd6b1d6c6b0 "The operation couldn’t be completed. No such file or directory"})
I have also tried,
- putting in the apostrophe in the command string
- changing the command in array string as suggested my few sites
but non of them worked.
Please advice if i did anything wrong in arranging my command or any syntax error that i made. Thanks in advance.
See Question&Answers more detail:os