Posts

Showing posts with the label subprocess

Running a subprocess with Dart and reading its output

Starting a foreign program, and reading its standard output stream is useful, and here is an example of listing the root directory. void main() { Process p = new Process('/bin/ls', ['/']); p.start(); StringInputStream stdoutStream = new StringInputStream(p.stdout); print(stdoutStream.read()); p.close(); } Notes: Argument list does not include the executable name like it usually does Use a StringInputStream to read an InputStream as a String Close the process or the script will hang forever Comments on Google+ .

Spawning subprocess with PyGTK using Twisted

Well, it is an age-old problem: How to schedule long-running tasks withing a GUI main loop (in our case PyGTK). There are a few ways: Use Python's subprocess module and select on the pipe with gobject's io_add_watch Use GTK's built in subprocess spawning abilities Use Twisted 1 & 2 are reasonable approaches, and they both work. Of course 1 won't work on Win32. The only problem with both 1 & 2 is that they use gobject's polling functions to achieve asynchronicity. This is nice when we are forced in a PyGTK main loop, but really not nice when the application wants to run in command line mode, and we really want to be able to share the execution code between different UIs, including perhaps other toolkits. Enter Twisted. We need to do two things with Twisted: Make sure Twisted knows we are running with PyGTK Launch the process Making sure Twisted knows that we are running inside PyGTK is quite easy (though I imagine the implementation was painful). To do this, ...