aspose file tools*
The moose likes Java in General and the fly likes Runtime.exec() Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Runtime.exec()" Watch "Runtime.exec()" New topic
Author

Runtime.exec()

A. Wolf
Ranch Hand

Joined: Sep 28, 2003
Posts: 57
Hi,
I've been using Runtime to execute basic commands on my Mac, and also through a local network on my moms PC. Worked fine until a little bit ago. now I just get errors on the pc, but not on my mac.
does this have to do with 1.4.1 to 1.4.2 update? that would be weird wouldnt it?
on the pc i get the following error:
C:\Dokumente und Einstellungen\Susan\Desktop>java something
java.io.IOException: CreateProcess: dir error=2
at java.lang.Win32Process.create(Native Method)
at java.lang.Win32Process.<init>(Unknown Source)
at java.lang.Runtime.execInternal(Native Method)
at java.lang.Runtime.exec(Unknown Source)
at java.lang.Runtime.exec(Unknown Source)
at java.lang.Runtime.exec(Unknown Source)
at java.lang.Runtime.exec(Unknown Source)
at something.main(something.java:36)
here is the code.

all help appreciated thank you
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
This might get tricky ... I remember dir is one of those commands that is not a program so it can't be launched as a program. You can run command.com (cmd.com on some systems?) and then send "dir" to its standard input. Oh, and then send "exit" to make command.com end. You can try all that in a DOS window. You may be able to launch a bat file that does dir for you. Much simpler!


A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
Dmitry Melnik
Ranch Hand

Joined: Dec 18, 2003
Posts: 328
Your code tries to read from streams when the process associated with them has been completed. Might be the case.
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
I wondered about those stream readers. Each just reads until end on the main thread. I'm not sure that will fly, but it's worth trying. I did a runtime() thingie once and made separate threads to read the stdout and errout. They ALWAYS finished well AFTER the waitfor() returned. I guessed that output must get buffered up somewhere and my asynchronous reads were relatively slow compared to the process's writes.
Taikonaut five
Greenhorn

Joined: Mar 11, 2004
Posts: 3
I use rt.exec("cmd.exe"),although windows create "CMD.EXe" process, But
I can't see it. I think that "cmd.exe" can't create a really process.
Who tell me how to do it!
Taikonaut five
Greenhorn

Joined: Mar 11, 2004
Posts: 3
The Runtime.exec methods create a native process and return an instance of a subclass of Process that can be used to control the process and obtain information about it. The class Process provides methods for performing input from the process, performing output to the process, waiting for the process to complete, checking the exit status of the process, and destroying (killing) the process.
The Runtime.exec methods may not work well for special processes on certain native platforms, such as native windowing processes, daemon processes, Win16/DOS processes on Microsoft Windows, or shell scripts. The created subprocess does not have its own terminal or console. All its standard io (i.e. stdin, stdout, stderr) operations will be redirected to the parent process through three streams (Process.getOutputStream(), Process.getInputStream(), Process.getErrorStream()). The parent process uses these streams to feed input to and get output from the subprocess. Because some native platforms only provide limited buffer size for standard input and output streams, failure to promptly write the input stream or read the output stream of the subprocess may cause the subprocess to block, and even deadlock.
The subprocess is not killed when there are no more references to the Process object, but rather the subprocess continues executing asynchronously.
There is no requirement that a process represented by a Process object execute asynchronously or concurrently with respect to the Java process that owns the Process object.
Dirk Schreckmann
Sheriff

Joined: Dec 10, 2001
Posts: 7023
Moving this fancy talk to the Intermediate forum...


[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Runtime.exec()