From: Yang W. <yw...@pr...> - 2002-02-12 18:32:12
|
Kevin, Thanks for your reponse. Of the two suggestions, the first one got me an error: >>> import java >>> import java.lang >>> import os >>> java.lang.Runtime.getRuntime().exec("start StartDmServices.bat") Traceback (innermost last): File "<console>", line 1, in ? java.io.IOException: CreateProcess: start StartDmServices.bat error=3D2 at java.lang.Win32Process.create(Native Method) at java.lang.Win32Process.<init>(Win32Process.java:66) at java.lang.Runtime.execInternal(Native Method) at java.lang.Runtime.exec(Runtime.java:551) at java.lang.Runtime.exec(Runtime.java:418) at java.lang.Runtime.exec(Runtime.java:361) at java.lang.Runtime.exec(Runtime.java:325) at java.lang.reflect.Method.invoke(Native Method) at org.python.core.PyReflectedFunction.__call__(PyReflectedFunction.java ) at org.python.core.PyMethod.__call__(PyMethod.java) at org.python.core.PyObject.__call__(PyObject.java) at org.python.core.PyInstance.invoke(PyInstance.java) at org.python.pycode._pyx5.f$0(<console>:1) at org.python.pycode._pyx5.call_function(<console>) at org.python.core.PyTableCode.call(PyTableCode.java) at org.python.core.PyCode.call(PyCode.java) at org.python.core.Py.runCode(Py.java) at org.python.core.Py.exec(Py.java) at org.python.util.PythonInterpreter.exec(PythonInterpreter.java) at org.python.util.InteractiveInterpreter.runcode(InteractiveInterpreter .java) at org.python.util.InteractiveInterpreter.runsource(InteractiveInterpret er.java) at org.python.util.InteractiveInterpreter.runsource(InteractiveInterpret er.java) at org.python.util.InteractiveConsole.push(InteractiveConsole.java) at org.python.util.InteractiveConsole.interact(InteractiveConsole.java) at org.python.util.jython.main(jython.java) java.io.IOException: java.io.IOException: CreateProcess: start StartDmServices.b at error=3D2 I did "start StartDmServices.bat" in DOS window and it works. Then I used a non existing bat file and surprise, got the same error: >>> java.lang.Runtime.getRuntime().exec("start NoExist.bat") Traceback (innermost last): File "<console>", line 1, in ? java.io.IOException: CreateProcess: start NoExist.bat error=3D2 at java.lang.Win32Process.create(Native Method) at java.lang.Win32Process.<init>(Win32Process.java:66) at java.lang.Runtime.execInternal(Native Method) at java.lang.Runtime.exec(Runtime.java:551) at java.lang.Runtime.exec(Runtime.java:418) at java.lang.Runtime.exec(Runtime.java:361) at java.lang.Runtime.exec(Runtime.java:325) at java.lang.reflect.Method.invoke(Native Method) at org.python.core.PyReflectedFunction.__call__(PyReflectedFunction.java ) at org.python.core.PyMethod.__call__(PyMethod.java) at org.python.core.PyObject.__call__(PyObject.java) at org.python.core.PyInstance.invoke(PyInstance.java) at org.python.pycode._pyx6.f$0(<console>:1) at org.python.pycode._pyx6.call_function(<console>) at org.python.core.PyTableCode.call(PyTableCode.java) at org.python.core.PyCode.call(PyCode.java) at org.python.core.Py.runCode(Py.java) at org.python.core.Py.exec(Py.java) at org.python.util.PythonInterpreter.exec(PythonInterpreter.java) at org.python.util.InteractiveInterpreter.runcode(InteractiveInterpreter .java) at org.python.util.InteractiveInterpreter.runsource(InteractiveInterpret er.java) at org.python.util.InteractiveInterpreter.runsource(InteractiveInterpret er.java) at org.python.util.InteractiveConsole.push(InteractiveConsole.java) at org.python.util.InteractiveConsole.interact(InteractiveConsole.java) at org.python.util.jython.main(jython.java) java.io.IOException: java.io.IOException: CreateProcess: start NoExist.bat error =3D2 But I checked the bat file name again and again and with cap/uncap. All got the same error. I really appreciate if you can point to what I did wrong. Thanks! 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. Yang -----Original Message----- From: Kevin Butler [mailto:kb...@ca...] Sent: Monday, February 11, 2002 7:53 AM To: Yang Wang Cc: jyt...@li... Subject: Re: [Jython-users] start a Window2K program in a separate window andbackto Jython Yang Wang wrote: >=20 > Hi All, >=20 > I am trying to use os.system("start mine.bat") to start a program in a > separate window. But the problem is that the control remains in the new > window and did not go back to the Jython window at all. Until I exit > the "mine.bat", the prompt in Jython began to show up. From "help start" on NT/4: > When executing an application that is a 32-bit GUI application, CMD.EXE > does not wait for the application to terminate before returning to > the command prompt. This new behavior does NOT occur if executing > within a command script. > Did I use the right command to do this? =20 Yes. Maybe. system() starts a command and waits for it to complete. > I looked at other Python > commands such as os.execl() but when I try it on Jython, it would say > that "AttributeError: class 'org.python.modules.os' has no attribute > 'execl'". RSN I'll implement the os.exec() functions, but I haven't gotten around to it yet. Currently, to have your app continue running after launching the command, you can either: - run the command as java.lang.runtime.getRuntime().exec([ "cmd.exe", "/c", "mine.bat" ]) - run system in a separate thread as thread.start_new_thread( os.system, ("mine.bat",)) Note that either approach may leave your jython application without the focus (depends on what the MS Window Manager decides to do), so you may need to add a "setFocus" command to your jython GUI application. kb _______________________________________________ Jython-users mailing list Jyt...@li... https://lists.sourceforge.net/lists/listinfo/jython-users |
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 |