using subprocess.Popen does not suppress terminal window on Windows
Alf P. Steinbach
alfps at start.no
Fri Jun 18 12:40:13 EDT 2010
* Steven, on 18.06.2010 18:23:
> I am calling a ruby program from a python gui and using
> subprocess.Popen in Windows XP using python 2.6. Unfortunately,
> whenever the ruby program is called a blank command window appears on
> screen, annoying my users. Is there a way to suppress this behaviour?
Yes, launch the GUI subsystem Ruby interpreter.
<example of="finding that beast">
C:\projects\blog\cppx\exception_translation\examples> set pathe
PATHEXT=.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.CJS;.JS;.JSE;.WSF;.WSH;.RB;.RBW
C:\projects\blog\cppx\exception_translation\examples> assoc .rb
.rb=rbFile
C:\projects\blog\cppx\exception_translation\examples> ftype rbfile
rbfile="C:\PROGRA~1\@utilities\ruby\bin\ruby.exe" "%1" %*
C:\projects\blog\cppx\exception_translation\examples> assoc .rbw
.rbw=rbwFile
C:\projects\blog\cppx\exception_translation\examples> ftype rbwfile
rbwfile="C:\PROGRA~1\@utilities\ruby\bin\rubyw.exe" "%1" %*
C:\projects\blog\cppx\exception_translation\examples> _
</example>
OK, it's called 'rubyw.exe'.
You can read about console and GUI subsystem for the complete beginner
programmer at <url: http://tinyurl.com/programmingbookP3>, ch. 1 (hope I got the
URL right).
> Below is a minimal program that demonstrates the problem. The problem
> does not manifest if the python program is launched via the command
> line. To duplicate launch from Windows Explorer by double-clicking on
> the python file.
>
> --- call_double.pyw ---
> from subprocess import *
> import time
>
> time.sleep(3) # to show that command window is result of call to Popen
> p = Popen(['ruby.exe', 'double.rb'], stdin=PIPE, stdout=PIPE,
> stderr=PIPE)
Change this to 'rubyw.exe' when running in Windows.
Note that that it's perfectly OK to pipe to or from a GUI subsystem program.
> results = open('results.txt', 'w')
> for n in range(10):
> p.stdin.write("%d\n" % n)
> result = p.stdout.readline().strip()
> results.write('double(%s) => %2s\n' % (n, result))
> results.close()
>
> --- end of call_double.pyw ---
>
> --- double.rb ---
> while true
> puts $stdin.gets().strip!.to_i * 2
> STDOUT.flush
> end
Cheers & hth.,
- Alf
--
blog at <url: http://alfps.wordpress.com>
More information about the Python-list
mailing list