Created
April 14, 2015 20:04
-
-
Save SteveGilham/015734bd2d6084d6cb3f to your computer and use it in GitHub Desktop.
Spawn a process in FePy
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
import System | |
from System.Diagnostics import * | |
from System.IO import * | |
#--------------------------------------------------- | |
def spawn(cmd, args, wait=True): | |
"""Spawn a process running executable 'cmd' with the rest of the command line given by | |
'args'. If wait is given as False, the rest of the script keeps on going while the sub-process | |
is running. By default, the script waits for the sub-process to finish before resuming. | |
The usual reminder about DOS built-in commands like 'del' applies -- you have to give cmd='cmd' | |
and args = '/C del ' plus what you would give as an argument to 'del'. | |
""" | |
# Fire off a separate process | |
# Optional embellishments presented as comments | |
proc = Process() | |
start = ProcessStartInfo() | |
start.FileName = cmd | |
start.Arguments = args | |
start.UseShellExecute = 0 # needed to allow redirection | |
start.RedirectStandardOutput = 1 # ask for redirection | |
proc.StartInfo = start | |
# print cmd+" "+args | |
try : | |
proc.Start() | |
if wait: | |
proc.WaitForExit() | |
#line = proc.StandardOutput.ReadToEnd() | |
#print line | |
except: | |
#print "FAILED" | |
pass | |
#--------------------------------------------------- | |
if __name__ == '__main__' : | |
spawn("cmd", "/c type spawn.py") | |
sys32dir = System.Environment.GetFolderPath(System.Environment.SpecialFolder.System) | |
paint = "\""+sys32dir+"\\mspaint.exe\"" | |
spawn(paint, "", False) | |
print "Done - but paint should still be showing" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment