From: Kevin B. <kb...@ca...> - 2002-02-12 18:47:52
|
Yang Wang wrote: [problems with Runtime.exec()] The problem you're having with 'Runtime.exec' is that 'exec' only executes programs, passing arguments to the programs. Since there is no program 'start.exe' (or start.com), exec fails to execute your command-line. os.system, by contrast, is defined to execute its command-line in a shell. 'start' is a shell command in the cmd.com shell, so you need to follow os.system's example and pass the 'start...' as a command to cmd.exe (command.com in DOS-descendants): >>> from java.lang import * >>> Runtime.getRuntime().exec( "start notepad.exe" ) Traceback (innermost last): File "<console>", line 1, in ? java.io.IOException: CreateProcess: start notepad.exe error=2 at java.lang.Win32Process.create(Native Method) ... >>> Runtime.getRuntime().exec( "notepad.exe" ) java.lang.Win32Process@64f8d4 >>> Runtime.getRuntime().exec( "cmd /c start notepad.exe" ) java.lang.Win32Process@7ae93e >>> Runtime.getRuntime().exec( "cmd /c start d:/temp/kb.bat" ) java.lang.Win32Process@2b7bd9 >>> > BTW, the second method (start a new thread) works but the problem is > that the output crowds the window. It is kind of inconvenient when > working in interactive mode. Sorry, didn't realize you were working with console apps. Working with os.system, you have your native shell's redirection capabilities: >>> thread.start_new_thread( os.system, ( "cat d:/temp/readme.txt > d:/temp/output", )) >>> kb |