Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #37650

Re: a crazy java problem

From Arne Vajhøj <arne@vajhoej.dk>
Newsgroups comp.lang.java.programmer
Subject Re: a crazy java problem
Date 2017-11-10 22:53 -0500
Organization Aioe.org NNTP Server
Message-ID <ou5s7h$97m$1@gioia.aioe.org> (permalink)
References <33ab661b-810a-4d40-86ef-907752ec35aa@googlegroups.com> <37cbaf57-b52e-4f12-93c1-e3da6b01c9d9@googlegroups.com>

Show all headers | View raw


On 11/10/2017 9:43 PM, mcheung63@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

Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Find similar | Unroll thread


Thread

a crazy java problem mcheung63@gmail.com - 2017-11-10 18:41 -0800
  Re: a crazy java problem mcheung63@gmail.com - 2017-11-10 18:43 -0800
    Re: a crazy java problem Arne Vajhøj <arne@vajhoej.dk> - 2017-11-10 22:53 -0500

csiph-web