Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Runtime exec problems with process with multiple args

Reply
Thread Tools

Runtime exec problems with process with multiple args

 
 
Bob Connell
Guest
Posts: n/a
 
      03-03-2004
I have a C executable program which takes several arguments that I want
to be able to spawn off using the Java Runtime and Process classes on a
Windows XP workstation.

Failed Solution 1:
----------------
I have found that if I start my process as such...

pe = runt.exec("cmd.exec /c myprocess.exe -arg1 -arg2");

(where runt is: Runtime runt = Runtime.getRuntime(); )

.... there are no problems with the execution but I cannot kill my
process (which may be needed) with the Process destroy() method. It
seems to kill the cmd.exe but the sub-sub process (e.g., myprocess.exe)
continues to run.

Failed Solution 2:
------------------

I have also found that if I run as the following (without the cmd
command)...

pe = runt.exec("myprocess.exe -arg1 -arg2");

My process will hang but I can kill it. I am assuming that it hangs
because it does recognize the arguments

Anyone have a solution to this problem or what I should attempt next?

NOTE: I have tried organizing the command into an array without any
success.

thanks!

Bob

 
Reply With Quote
 
 
 
 
Matt Humphrey
Guest
Posts: n/a
 
      03-03-2004

"Bob Connell" <(E-Mail Removed)> wrote in message news:(E-Mail Removed)...
I have a C executable program which takes several arguments that I want to be able to spawn off using the Java Runtime and Process classes on a Windows XP workstation.
Failed Solution 1:
----------------
I have found that if I start my process as such...

pe = runt.exec("cmd.exec /c myprocess.exe -arg1 -arg2");

(where runt is: Runtime runt = Runtime.getRuntime(); )

... there are no problems with the execution but I cannot kill my process (which may be needed) with the Process destroy() method. It seems to kill the cmd.exe but the sub-sub process (e.g., myprocess.exe) continues to run.

Failed Solution 2:
------------------

I have also found that if I run as the following (without the cmd command)...

pe = runt.exec("myprocess.exe -arg1 -arg2");

My process will hang but I can kill it. I am assuming that it hangs because it does recognize the arguments

Anyone have a solution to this problem or what I should attempt next?

NOTE: I have tried organizing the command into an array without any success.

thanks!

Bob

Does your executable generate any data on standard output or standard error? If you do not gobble up that output, it may fill the process's buffer and your executable will hang. Also, looking at the output may help you figure out what's actually wrong.

Cheers,
Matt Humphrey http://www.velocityreviews.com/forums/(E-Mail Removed) http://www.iviz.com/
 
Reply With Quote
 
 
 
 
Rajesh Patel
Guest
Posts: n/a
 
      03-03-2004
I have seen programs that expect you to read the
output of STDERR and STDOUT.

For example, perl will print X bytes of data to
it's STDOUT and will halt until somebody reads it.

The best way to do this is to spawn off a separate thread
to read the STDERR and STDOUT from your process.

If this is your problem it explains why CMD is working because
it's doing that for you.

Also, I would avoid string version of Runtime.getRuntime().exec like
the plague. You're not dealing with a command interpreter so it
will break the following:
someprog.exe -arg1="c:\Program Files\someArg"

into

exe=someprog.exe
arg1=-arg1="c:\Program
arg1=Files\someArg"


not exactly what you would expect.
The array version does not have this problem.

Raj

Bob Connell wrote:

> I have a C executable program which takes several arguments that I want
> to be able to spawn off using the Java Runtime and Process classes on a
> Windows XP workstation.
>
> Failed Solution 1:
> ----------------
> I have found that if I start my process as such...
>
> pe = runt.exec("cmd.exec /c myprocess.exe -arg1 -arg2");
>
> (where runt is: Runtime runt = Runtime.getRuntime(); )
>
> ... there are no problems with the execution but I cannot kill my
> process (which may be needed) with the Process destroy() method. It
> seems to kill the cmd.exe but the sub-sub process (e.g., myprocess.exe)
> continues to run.
>
> Failed Solution 2:
> ------------------
>
> I have also found that if I run as the following (without the cmd
> command)...
>
> pe = runt.exec("myprocess.exe -arg1 -arg2");
>
> My process will hang but I can kill it. I am assuming that it hangs
> because it does recognize the arguments
>
> Anyone have a solution to this problem or what I should attempt next?
>
> NOTE: I have tried organizing the command into an array without any
> success.
>
> thanks!
>
> Bob
>


 
Reply With Quote
 
John C. Bollinger
Guest
Posts: n/a
 
      03-03-2004
Bob Connell wrote:

> I have a C executable program which takes several arguments that I want
> to be able to spawn off using the Java Runtime and Process classes on a
> Windows XP workstation.
>
> Failed Solution 1:
> ----------------
> I have found that if I start my process as such...
>
> pe = runt.exec("cmd.exec /c myprocess.exe -arg1 -arg2");
>
> (where runt is: Runtime runt = Runtime.getRuntime(); )
>
> ... there are no problems with the execution but I cannot kill my
> process (which may be needed) with the Process destroy() method. It
> seems to kill the cmd.exe but the sub-sub process (e.g., myprocess.exe)
> continues to run.
>
> Failed Solution 2:
> ------------------
>
> I have also found that if I run as the following (without the cmd
> command)...
>
> pe = runt.exec("myprocess.exe -arg1 -arg2");
>
> My process will hang but I can kill it. I am assuming that it hangs
> because it does recognize the arguments


It would be wise to investigate the reason for the failure more fully.
In my opinion it is unlikely that the problem has anything to do with
the arguments if the specified command would be valid at a shell prompt.

> Anyone have a solution to this problem or what I should attempt next?


You should read the Process' output and error streams to look for
diagnostic messages. Depending on the external program, it may be the
case that it has run to completion and is a zombie -- to clear it you
might need to execute the Process' waitFor() method. Do read the API
docs for the Process class.

My best guess as to what is actually happening is that the external
executable is not found in whatever executable path is in effect, which
may be different from the one set up by a CMD shell.

> NOTE: I have tried organizing the command into an array without any
> success.


All the more reason to think that the problem is not with the arguments.


John Bollinger
(E-Mail Removed)

 
Reply With Quote
 
nos
Guest
Posts: n/a
 
      03-03-2004

"John C. Bollinger" <(E-Mail Removed)> wrote in message
news:c25gq8$d75$(E-Mail Removed)...
> Bob Connell wrote:
>
> > I have a C executable program which takes several arguments that I want
> > to be able to spawn off using the Java Runtime and Process classes on a
> > Windows XP workstation.
> >
> > Failed Solution 1:
> > ----------------
> > I have found that if I start my process as such...
> >
> > pe = runt.exec("cmd.exec /c myprocess.exe -arg1 -arg2");
> >
> > (where runt is: Runtime runt = Runtime.getRuntime(); )
> >
> > ... there are no problems with the execution but I cannot kill my
> > process (which may be needed) with the Process destroy() method. It
> > seems to kill the cmd.exe but the sub-sub process (e.g., myprocess.exe)
> > continues to run.
> >
> > Failed Solution 2:
> > ------------------
> >
> > I have also found that if I run as the following (without the cmd
> > command)...
> >
> > pe = runt.exec("myprocess.exe -arg1 -arg2");
> >
> > My process will hang but I can kill it. I am assuming that it hangs
> > because it does recognize the arguments


Aye that's it, you just have to guess and put in some arguments that this
sneaky bastard program doesn't recognize.


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
problem with multiword args and Runtime.exec() Aryeh M. Friedman Java 3 01-11-2013 07:44 PM
Runtime.exec(String[]) Doesn't Always Work, bBut Runtime.exec(String) Does Hal Vaughan Java 11 05-22-2006 04:49 PM
Is there a class or method to construct url args or extract url args? Ken Varn ASP .Net 2 06-22-2005 12:26 PM
args v. *args passed to: os.path.join() Pierre Fortin Python 2 09-18-2004 06:59 PM
When passing functions as args,how to pass extra args for passed function? python@sarcastic-horse.com Python 3 09-17-2003 12:25 AM



Advertisments