On 11/10/2017 9:43 PM,
mche...@gmail.com wrote:
>
mche...@gmail.com於 2017年11月11日星期六 UTC+8上午10時41分45秒寫道:
>> this code can run successfull in a simple java main():
>> String str = CommonLib.runCommand("C:\\Program Files (x86)\\Graphviz2.38\\bin\\dot.exe -Tpng C:\\Users\\Peter\\AppData\\Local\\Temp\\1.asm6434829820851445658.dot -o C:\\Users\\Peter\\desktop\\1.asm3568795673124410656.png");
>> But if running inside the netbeans plugin module, it throws an exception:
>>
>> java.io.IOException: CreateProcess error=2, The system cannot find the file specified
>> Caused: java.io.IOException: Cannot run program "C:\Program": CreateProcess error=2, The system cannot find the file specified
>> Any hints?
> public static String runCommand(String command, int skipLine) throws Exception {
> Process p = Runtime.getRuntime().exec(command);
I am more puzzled over why it sometimes work.
As I read the JavaDoc for Runtime.exec overloads then command line
get parsed to parts simply by splitting at spaces. That does not
find the correct command.
So I will suggest:
String str = CommonLib.runCommand(new String[] { "C:\\Program Files
(x86)\\Graphviz2.38\\bin\\dot.exe", "-Tpng",
"C:\\Users\\Peter\\AppData\\Local\\Temp\\1.asm6434829820851445658.dot",
"-o", "C:\\Users\\Peter\\desktop\\1.asm3568795673124410656.png" });
public static String runCommand(String[] cmdarr, int skipLine) throws
Exception {
Process p = Runtime.getRuntime().exec(cmdarr);
Arne