Re: Activating Batch Files from Python
Jeff Groves wrote: How would I do that? As I've said, I haven't found a Python command that lets you send multiple commands to the same shell yet. If I could, my problem would be solved. any reason why you cannot create a temp .bat, consisting of: setvar.bat prog1.exe prog2.exe and then execute it form perl? -- http://mail.python.org/mailman/listinfo/python-list
Re: Activating Batch Files from Python
In article [EMAIL PROTECTED], Jeff Groves [EMAIL PROTECTED] wrote: How about sourcing it from a shell, then using that same shell instance to run the programs? How would I do that? As I've said, I haven't found a Python command that lets you send multiple commands to the same shell yet. If I could, my problem would be solved. What about os.popen? Otherwise there's the usual fork/exec thing. -- http://mail.python.org/mailman/listinfo/python-list
Re: Activating Batch Files from Python
On 4/18/2006 11:39 PM, Jeff Groves wrote: I'm writing a launcher that should do the following: 1. Activate a .bat file to set environmental variables. 2. Start 3 programs, using said environmental variables as arguments. However, I can't get the environmental variables to stick because all of Pythons' system start/open functions split off into their own little subshells, therefore the .bat file doesn't affect the main shell. How can I use the .bat file to set environmental vars from Python? Resource Kit has SETX, but better is SETENV by Vincent Fatica http://barnyard.syr.edu/~vefatica/ C:\_Utilssetenv /? SETENV syntax: To set or change the value of a variable: User environment: setenv -u name value(also /u) Machine environment:setenv -m name value(also /m) Default user environment: setenv -d name value(also /d) Volatile environment: setenv -v name value(also /v) To display a variable: setenv -u|-m|-d|-v name To delete a variable: setenv -u|-m|-d|-v name -delete (also /delete) To display an environment: setenv -u|-m|-d|-v Use double-quotes around values containing spaces. If a variable name or value is to CONTAIN a double-quote, escape that double-quote as \ Return codes: 0 = success1 = variable not found 2 = access denied 3 = other error 4 = SETENV has shown this syntax message Requested output goes to STDOUT; help and error messages to STDERR. -- http://mail.python.org/mailman/listinfo/python-list
Re: Activating Batch Files from Python
Jeff Groves [EMAIL PROTECTED] wrote: I'm writing a launcher that should do the following: 1. Activate a .bat file to set environmental variables. 2. Start 3 programs, using said environmental variables as arguments. However, I can't get the environmental variables to stick because all of Pythons' system start/open functions split off into their own little subshells, therefore the .bat file doesn't affect the main shell. How can I use the .bat file to set environmental vars from Python? One very real possibility is to parse your .bat files by hand, and make the changes to your os.environ. Your subprocesses inherit that. .BAT files are easy to parse, especially if they're just a bunch of 'set' statements. -- - Tim Roberts, [EMAIL PROTECTED] Providenza Boekelheide, Inc. -- http://mail.python.org/mailman/listinfo/python-list
Re: Activating Batch Files from Python
Jeff Groves wrote: I'm writing a launcher that should do the following: 1. Activate a .bat file to set environmental variables. 2. Start 3 programs, using said environmental variables as arguments. However, I can't get the environmental variables to stick because all of Pythons' system start/open functions split off into their own little subshells, therefore the .bat file doesn't affect the main shell. That's right. That is how enviromental variables work regardless of programming language. How can I use the .bat file to set environmental vars from Python? If it is your bat file, forget about it. Set the variables in your Python program using os.environ. If it is a 3rd party bat file, the best you can do is to copy it, add (at the end) a command to dump all enviromental variables to a temp file like this: set dump_file.txt, parse the dump file to see what variables changed and set the variables using os.environ. -- http://mail.python.org/mailman/listinfo/python-list
Re: Activating Batch Files from Python
In article [EMAIL PROTECTED], Jeff Groves [EMAIL PROTECTED] wrote: How can I use the .bat file to set environmental vars from Python? How about sourcing it from a shell, then using that same shell instance to run the programs? -- http://mail.python.org/mailman/listinfo/python-list
Re: Activating Batch Files from Python
How about sourcing it from a shell, then using that same shell instance to run the programs? How would I do that? As I've said, I haven't found a Python command that lets you send multiple commands to the same shell yet. If I could, my problem would be solved. -- http://mail.python.org/mailman/listinfo/python-list
Re: Activating Batch Files from Python
On 2006-04-19, Jeff Groves [EMAIL PROTECTED] wrote: I'm writing a launcher that should do the following: 1. Activate a .bat file to set environmental variables. 2. Start 3 programs, using said environmental variables as arguments. However, I can't get the environmental variables to stick because all of Pythons' system start/open functions split off into their own little subshells, therefore the .bat file doesn't affect the main shell. How can I use the .bat file to set environmental vars from Python? You can try launching a single shell with subprocess.Popen, and run everything inside that: from subprocess import * p = Popen(cmd, stdin = PIPE, stdout = PIPE) output, err = p.communicate( vars.bat prog1.exe prog2.exe prog3.exe ) print output I can't test this because I don't have a Windows system. Otherwise, as others have suggested, replace vars.bat with modifications to os.environ. -- http://mail.python.org/mailman/listinfo/python-list
Re: Activating Batch Files from Python
On 2006-04-19, Jeff Groves [EMAIL PROTECTED] wrote: How about sourcing it from a shell, then using that same shell instance to run the programs? How would I do that? As I've said, I haven't found a Python command that lets you send multiple commands to the same shell yet. If I could, my problem would be solved. If I understood correctly I think the idea is to run vars.bat first, then run the Python program in _that_ shell (so it inherits the environment) and then launch the other programs from the Python program. i.e. C:\ vars.bat C:\ python launcher.py You could put those commands in a batch file. So the outermost thing you run is a batch file, which starts Python, which starts the other programs. Seems quite a neat solution. -- http://mail.python.org/mailman/listinfo/python-list
Activating Batch Files from Python
I'm writing a launcher that should do the following: 1. Activate a .bat file to set environmental variables. 2. Start 3 programs, using said environmental variables as arguments. However, I can't get the environmental variables to stick because all of Pythons' system start/open functions split off into their own little subshells, therefore the .bat file doesn't affect the main shell. How can I use the .bat file to set environmental vars from Python? -- http://mail.python.org/mailman/listinfo/python-list