Win32_Process.Create -- not starting process
I am using Python to create a process on another computer. Both computers are on the same domain with admin privileges. On computer B I have a batch script which starts a python script. From computer A I am doing the following: import wmi w = wmi.WMI("1.2.3.4") p = w.new("Win32_Process") pid, retVal = p.Create(CommandLine="C:\\a_script.bat") print pid, retVal The output I get is, 1218 0 0 = "Successful Completion" however the python script that is called from the batch script never seems to run or at least only for a split second. Sometimes I see python.exe appear in the task manager on computer B for a split second then it goes away. So I went to computer B and double clicked on the batch script, and sure enough a command opened up and the python script was running...and stayed running...no problem. I should mention, that sometimes it will execute the batch script and the Python script will run and stay running. That has only happened after trying to do "p.Create(CommandLine)" more than once, but not every time I try. Any ideas why its not working for me remotelyor why its random? These are win xp machines with no firewalls running. -- http://mail.python.org/mailman/listinfo/python-list
RE: Win32_Process.Create -- not starting process
[abcd] | I am using Python to create a process on another computer. Both | computers are on the same domain with admin privileges. | | On computer B I have a batch script which starts a python | script. From computer A I am doing the following: | | import wmi | w = wmi.WMI("1.2.3.4") | p = w.new("Win32_Process") | pid, retVal = p.Create(CommandLine="C:\\a_script.bat") | print pid, retVal | | The output I get is, 1218 0 0 = "Successful Completion" | however the python script that is called from the batch script | never seems to run or at least only for a split second. Sometimes I | see python.exe appear in the task manager on computer B for a split | second then it goes away. So I went to computer B and double clicked | on the batch script, and sure enough a command opened up and | the python script was running...and stayed running...no problem. | I should mention, that sometimes it will execute the batch script and | the Python script will run and stay running. That has only happened | after trying to do "p.Create(CommandLine)" more than once, but not | every time I try. | | Any ideas why its not working for me remotelyor why its random? | These are win xp machines with no firewalls running. OK, let me say up front: there's nothing terribly obvious. Just in case you haven't, it's probably worth your running the latest wmi module -- 1.0rc6 at time of writing -- which makes slightly cleaner the interface to WMI classes. However, that's not the problem here, as the syntax you're using above works in 0.6b and in 1.0rc6 (I just tried both). I *think* that what you're seeing is that the script isn't running in the environment you're expecting, and is then swallowing the problem. Can you confirm whether or not the simplest possible Python script does indeed run and produce the expected result? You may well have to specify an explicit path for Python, give explicit paths for output files and so on. My test case, for example, which ran consistently, was: ## on the remote machine c:\python23\python c:\temp\wmi-test\test.py import os f = open ("c:\\temp\\wmi-test\\test.txt", "w") f.write ("%s\n" % os.getcwd ()) for k, v in os.environ.items (): f.write ("%s => %s\n" % (k, v)) f.close () ## on my machine import wmi c = wmi.WMI ("vogbp364") # obviously your remote machine name # # Slightly cleaner syntax new to wmi 1.0 # c.Win32_Process.Create (CommandLine=r"c:\temp\wmi-test\test.cmd") Obviously the extent to which you'll need to specify things will be affected by the system-level as opposed to user-level info on each machine. Hope that helps. Feel free to get back if it doesn't. TJG This e-mail has been scanned for all viruses by Star. The service is powered by MessageLabs. For more information on a proactive anti-virus service working around the clock, around the globe, visit: http://www.star.net.uk -- http://mail.python.org/mailman/listinfo/python-list
Re: Win32_Process.Create -- not starting process
Tim, Ok, well I verified that my python script and batch script are working properly. In fact, if I double click on the batch script (when its on Computer B), it starts the python script and the script runs fine with no problem. However when I try to execute the batch script from computer A using WMI it doesnt start. I say that because the python script that gets executed writes a status message to a file, and that does not occur as well as Python.exe does not show up in the task manager, even though Win32_Process.Create returns a PID and a 0 for the return code. So, if I try the same process a second time...it works. python.exe is running, status message is written to a file, etc. Is there some sort of initialization that needs to be done? Thanks -- http://mail.python.org/mailman/listinfo/python-list
RE: Win32_Process.Create -- not starting process
[abcd] |Ok, well I verified that my python script and batch script are | working properly. In fact, if I double click on the batch | script (when its on Computer B), it starts the python script and the script runs | fine with no problem. That's all very well, and it does confirm that there's no obvious error in the file, but by running the batch script *on* the computer it's on, you're running it in a particular environment / context etc. That environment isn't (necessarily) the same when you're running it across WMI. All I'm saying is that remotely executed jobs tend to be sensitive to environment issues which one is usually unconcerned about. This is as true for cron jobs or ssh-initiated execution on Unix as it is for WMI or service-driven execution under Windows. | However when I try to execute the batch script from computer A | using WMI it doesnt start. I say that because the python script that | gets executed writes a status message to a file, and that does not | occur as well as Python.exe does not show up in the task manager, even | though Win32_Process.Create returns a PID and a 0 for the return code. | So, if I try the same process a second time...it works. python.exe is | running, status message is written to a file, etc. Is there some sort | of initialization that needs to be done? Ok. That's certainly peculiar. I assume that the pid / zero-return is because the batch script itself is run; it's only the python script which isn't. Which doesn't explain why it runs the second time. Some obvious test cases: 1) If you have the batch script write something out to file by itself, does that happen? (eg SET > c:\temp.txt). Note - make sure the log file destination is absolute, ie c:\temp.txt, not just temp.txt. SET > c:\temp\test.txt 2) If you bypass the batch altogether, does that work, eg import wmi c = wmi.WMI () c.Win32_Process.Create (CommandLine=r"c:\python24\python c:\temp\test.py") If this isn't getting you anywhere, could you post up or send me privately your batch and python scripts? TJG This e-mail has been scanned for all viruses by Star. The service is powered by MessageLabs. For more information on a proactive anti-virus service working around the clock, around the globe, visit: http://www.star.net.uk -- http://mail.python.org/mailman/listinfo/python-list
Re: Win32_Process.Create -- not starting process
so far i tried adding SET > c:\tmp.txt start SET > c:\tmp2.txt ...and I saw both tmp files created but no python running. I still have to try skipping the batch file...i'll let u know. thanks -- http://mail.python.org/mailman/listinfo/python-list
Re: Win32_Process.Create -- not starting process
"abcd" <[EMAIL PROTECTED]> wrote: >.however the python script that is called from the batch script One thing I have learned about launching programs from batch files like this is that if the launched program tries to prompt the user for imput at the command line, everthing goes haywire since it has no shell to communicate with. It may crash, go into a loop, etc. Good luck, Matt -- http://mail.python.org/mailman/listinfo/python-list
Re: Win32_Process.Create -- not starting process
Tim, I am skipping using the batch file and only executing the python script directly...and so far it works fine. So now I have: pid, retVal = wmi.WMI("1.2.3.4").new("Win32_Process").Create(CommandLine="c:\python\python.exe c:\some_script.py") Thanks again...not sure why when using the batch file to start it wouldnt always work, but as long is it works now! -- http://mail.python.org/mailman/listinfo/python-list
RE: Win32_Process.Create -- not starting process
[abcd] | Tim, | I am skipping using the batch file and only executing the python | script directly...and so far it works fine. | | So now I have: | pid, retVal = | wmi.WMI("1.2.3.4").new("Win32_Process").Create(CommandLine="c: | \python\python.exe | c:\some_script.py") | | Thanks again...not sure why when using the batch file to start it | wouldnt always work, but as long is it works now! Thanks for letting me know. Hope it continues to work for you. BTW, I would recommend you either to use a raw string for that command line (r"c:\python\python.exe c:\xx.py") or to double up your slashes ("c:\\python\\python.exe c:\\xx.py"). As it happens \p has no special meaning that I'm aware of, but better safe than sorry... TJG This e-mail has been scanned for all viruses by Star. The service is powered by MessageLabs. For more information on a proactive anti-virus service working around the clock, around the globe, visit: http://www.star.net.uk -- http://mail.python.org/mailman/listinfo/python-list
Re: Win32_Process.Create -- not starting process
Tim Golden wrote: > BTW, I would recommend you either to use a raw string > for that command line (r"c:\python\python.exe c:\xx.py") or > to double up your slashes ("c:\\python\\python.exe c:\\xx.py"). > As it happens \p has no special meaning that I'm > aware of, but better safe than sorry... i used double slashes, i guess i didn't type it correctly here. Thanks for the reminder though. -- http://mail.python.org/mailman/listinfo/python-list
Re: Win32_Process.Create -- not starting process
On 2/14/2006 11:25 AM, abcd wrote: > I am using Python to create a process on another computer. Both > computers are on the same domain with admin privileges. > > On computer B I have a batch script which starts a python script. From > computer A I am doing the following: > > import wmi > w = wmi.WMI("1.2.3.4") > p = w.new("Win32_Process") > pid, retVal = p.Create(CommandLine="C:\\a_script.bat") > print pid, retVal > > The output I get is, 1218 0 0 = "Successful Completion" > .however the python script that is called from the batch script > never seems to run or at least only for a split second. Sometimes I > see python.exe appear in the task manager on computer B for a split > second then it goes away. So I went to computer B and double clicked > on the batch script, and sure enough a command opened up and the python > script was running...and stayed running...no problem. I should > mention, that sometimes it will execute the batch script and the Python > script will run and stay running. That has only happened after trying > to do "p.Create(CommandLine)" more than once, but not every time I > try. > > Any ideas why its not working for me remotelyor why its random? > These are win xp machines with no firewalls running. > Troubleshooting context issues seems the right track. Consider: -Start a_script.bat using %windir%\system32\runas.exe ([/noprofile | /profile] [/env] [/netonly] Play with parameters to set and explore context issues. -Use the (well respected) psexec.exe from Sysinternals to confirm remote execution using another means. -Also from Sysinternals get and use ProcessExplorer, FileMon, TDIMon and TCPMon Other (possibly insulting to mention, please forgive) win batch troubleshooting steps: -REM out "@echo off" if any. -Place a strategic "pause" in the batch to hold the command window open. -Direct output from commands in the bat to a file "set > c:\temp\bat_out1.txt" then look at the creator, owner, etc. Prophylactic measures & things that effect the user context behavior: -Check "launch folder windows in a seperate process" in Explorer/Tools/Folder Options/View or you will not be able to run explorer.exe as an alternate user. -Uncheck "use simple file sharing" in same as above. FWIW Getting runas to to fire cmd.exe, then a .bat can be tricky, I use this to wrap runas, maybe it will help: :: Wrapper for runas.exe :: If called with a parameter use it as target, otherwise start cmd.exe :: !Note: /savecred is is convenient, but not very secure! :: LAST EDIT EBS 2006-02-10 ::@echo off :: !Change _USER to domain and user to run as! set _USER=domain\user if %1! == ! ( %SYSTEMROOT%/system32/runas.exe /savecred /noprofile /user:%_USER% "cmd.exe cd /D c:\\\_utils\" goto END ) else ( %SYSTEMROOT%/system32/runas.exe /savecred /user:%_USER% "%~f1" ) :END ::DIAGNOSTIC pause exit -- http://mail.python.org/mailman/listinfo/python-list