From: pr144 <pr...@ya...> - 2018-08-12 14:58:27
|
I am running a Powershell script that executes a Task Manger scheduled job on a different Windows Server from the Jython script. I am having a problem capturing the return value, the Powershell scripts takes about 1-2 minutes, this is the code, pipe = subprocess.Popen(['powershell.exe', 'MY_SCRIPT.ps1',stdout=sys.stdout] This doesn't work, (it returns before Pwershell script completes), pipe.communicate() This just leaves the the Jython script running at the command prompt until I kill it, retCode=pipe.wait() What are the best options? Thank you, PR |
From: Suvarchal <suv...@gm...> - 2018-08-12 15:28:24
|
How about cmd=["echo","hello"] try: retval=subprocess.check_output(cmd) except OSError as e: retval=e Cheers, Suvi On Sun, Aug 12, 2018 at 10:58 AM pr144 via Jython-users < jyt...@li...> wrote: > I am running a Powershell script that executes a Task Manger scheduled job > on a different Windows Server from the Jython script. > > I am having a problem capturing the return value, the Powershell scripts > takes about 1-2 minutes, this is the code, > > pipe = subprocess.Popen(['powershell.exe', > 'MY_SCRIPT.ps1',stdout=sys.stdout] > > This doesn't work, (it returns before Pwershell script completes), > > pipe.communicate() > > This just leaves the the Jython script running at the command prompt until > I kill it, > > retCode=pipe.wait() > > What are the best options? > > Thank you, > PR > > > ------------------------------------------------------------------------------ > Check out the vibrant tech community on one of the world's most > engaging tech sites, Slashdot.org! http://sdm.link/slashdot > _______________________________________________ > Jython-users mailing list > Jyt...@li... > https://lists.sourceforge.net/lists/listinfo/jython-users > |
From: Peter O'R. <pr...@ya...> - 2018-08-13 17:21:16
|
Error says, AttributeError: 'module' objects\ has no attribute 'check_output' I need the \return code from this line, pipe = subprocess.Popen(['powershell.exe', 'MY_SCRIPT.ps1',stdout=sys.stdout] Peter On Sunday, August 12, 2018, 11:28:17 AM EDT, Suvarchal <suv...@gm...> wrote: How about cmd=["echo","hello"] try: retval=subprocess.check_output(cmd) except OSError as e: retval=e Cheers, Suvi On Sun, Aug 12, 2018 at 10:58 AM pr144 via Jython-users <jyt...@li...> wrote: I am running a Powershell script that executes a Task Manger scheduled job on a different Windows Server from the Jython script. I am having a problem capturing the return value, the Powershell scripts takes about 1-2 minutes, this is the code, pipe = subprocess.Popen(['powershell.exe', 'MY_SCRIPT.ps1',stdout=sys.stdout] This doesn't work, (it returns before Pwershell script completes), pipe.communicate() This just leaves the the Jython script running at the command prompt until I kill it, retCode=pipe.wait() What are the best options? Thank you, PR ------------------------------------------------------------------------------ Check out the vibrant tech community on one of the world's most engaging tech sites, Slashdot.org! http://sdm.link/slashdot_______________________________________________ Jython-users mailing list Jyt...@li... https://lists.sourceforge.net/lists/listinfo/jython-users |
From: <jem...@fr...> - 2018-08-13 20:38:04
|
If the Python module is not working for you, perhaps try java.lang.ProcessBuilder instead. Something like: import java pb=java.lang.ProcessBuilder('powershell.exe', 'MY_SCRIPT.ps1') # Redirect stdout as desired. p=pb.start() p.waitFor() print p.exitValue() On Mon, 13 Aug 2018 17:20:43 +0000 (UTC), Peter O'Reilly via Jython-users <jyt...@li...> wrote: > Error says, AttributeError: 'module' objects has no attribute > 'check_output' > I need the return code from this line, pipe = > subprocess.Popen(['powershell.exe', 'MY_SCRIPT.ps1',stdout=sys.stdout] > > Peter > > On Sunday, August 12, 2018, 11:28:17 AM EDT, Suvarchal wrote: > > How about > > cmd=["echo","hello"] > try: > retval=subprocess.check_output(cmd) > except OSError as e: > retval=e > > Cheers, > Suvi > > On Sun, Aug 12, 2018 at 10:58 AM pr144 via Jython-users wrote: > > I am running a Powershell script that executes a Task Manger scheduled > job on a different Windows Server from the Jython script. > > I am having a problem capturing the return value, the Powershell scripts > takes about 1-2 minutes, this is the code, > > pipe = subprocess.Popen(['powershell.exe', > 'MY_SCRIPT.ps1',stdout=sys.stdout] > > This doesn't work, (it returns before Pwershell script completes), > > pipe.communicate() > > This just leaves the the Jython script running at the command prompt > until I kill it, > > retCode=pipe.wait() > > What are the best options? > > Thank you, > PR > > ------------------------------------------------------------------------------ > Check out the vibrant tech community on one of the world's most > engaging tech sites, Slashdot.org! http://sdm.link/slashdot > [2]_______________________________________________ > Jython-users mailing list > Jyt...@li... [3] > https://lists.sourceforge.net/lists/listinfo/jython-users [4] > > > Links: > ------ > [1] mailto:jyt...@li... > [2] http://sdm.link/slashdot > [3] mailto:Jyt...@li... > [4] https://lists.sourceforge.net/lists/listinfo/jython-users |
From: Jeff A. <ja...@fa...> - 2018-08-13 22:25:13
|
==> script.ps1 <== echo "Hello World!" Exit 1234 ==> script.py <== import subprocess p = subprocess.Popen(['powershell.exe', '-File', '.\\script.ps1']) p.wait() print "exit status =", p.returncode ============== The p.wait() is important: https://docs.python.org/2/library/subprocess.html?highlight=check_output#subprocess.Popen.wait Now ... PS here> java -jar "C:\Jython\2.7.1-sa\jython-standalone-2.7.1.jar" script.py Hello World! exit status = 1234 Jeff Allen On 13/08/2018 18:20, Peter O'Reilly via Jython-users wrote: > Error says, > AttributeError: 'module' objects\ has no attribute 'check_output' > > I need the \return code from this line, > pipe = subprocess.Popen(['powershell.exe', > 'MY_SCRIPT.ps1',stdout=sys.stdout] > > > > > Peter > > |
From: pr144 <pr...@ya...> - 2018-08-13 23:32:36
|
The problem is I can see the powershell is executing a Windows task, but control never returns back to the calling Jython script..even after the task is complete. So Jython is never getting to p.returncode.. Seems like it's stuck on the p.wait() line... On 8/13/2018 6:25 PM, Jeff Allen wro > > ==> script.ps1 <== > echo "Hello World!" > Exit 1234 > > ==> script.py <== > import subprocess > p = subprocess.Popen(['powershell.exe', '-File', '.\\script.ps1']) > p.wait() > print "exit status =", p.returncode > > ============== > > The p.wait() is important: > https://docs.python.org/2/library/subprocess.html?highlight=check_output#subprocess.Popen.wait > > Now ... > > PS here> java -jar "C:\Jython\2.7.1-sa\jython-standalone-2.7.1.jar" > script.py > Hello World! > exit status = 1234 > > > Jeff Allen > On 13/08/2018 18:20, Peter O'Reilly via Jython-users wrote: >> Error says, >> AttributeError: 'module' objects\ has no attribute 'check_output' >> >> I need the \return code from this line, >> pipe = subprocess.Popen(['powershell.exe', >> 'MY_SCRIPT.ps1',stdout=sys.stdout] >> >> >> >> >> Peter >> >> > -- Thank you, Peter O'Reilly |
From: Jeff A. <ja...@fa...> - 2018-08-14 06:17:44
|
Hi Peter: From here it is a question of zeroing-in on the boundary between what works and what doesn't -- the usual debugging process. Does my simple example work for you, with the simple script? If even that fails for you, ask what powershell may be doing at start-up. It loads libraries from various default places. Maybe that hangs. There is a -NoProfile option to suppress some of it. And a -NonInteractive (?) I think probably simplifies i/o. You can look up the options. If the simple script works, then it seems to be something about your script. It is obviously more complicated than mine. If you start from my simple script and introduce your own by parts, where does it start to hang? You want to capture the output, but the way you show stdout captured is not what we see in the documentation (use PIPE). There are also warnings that when doing so, deadlock is possible but communicate() is a good choice. It seems to include the wait(). Here is a version of my example that captures the output: ==> script.py <== import subprocess p = subprocess.Popen(['powershell.exe', '-File', '.\\script.ps1'], stdout=subprocess.PIPE, stderr=subprocess.PIPE) r = p.communicate() print "stdout =", repr(r[0]) print "stderr =", repr(r[1]) print "exit status =", p.returncode I am using repr() in the output to make visible non-printing or non-ascii characters (bytes really) that may be a source of problems. PS here> java -jar "C:\Jython\2.7.1-sa\jython-standalone-2.7.1.jar" script.py stdout = 'Hello World!\r\n' stderr = '' exit status = 1234 Lastly, all this may equally be run under C Python, in case you suspect a divergence or broken installation. (Jython has to work hard to conceal various differences between Java Process API and the system call. Or maybe your library is bad.) It worked for me under IDLE. Jeff Jeff Allen On 14/08/2018 00:32, pr144 wrote: > > The problem is I can see the powershell is executing a Windows task, > but control never returns back to the calling Jython script..even > after the task is complete. > > So Jython is never getting to p.returncode.. > > Seems like it's stuck on the p.wait() line... > > > > On 8/13/2018 6:25 PM, Jeff Allen wro >> >> ==> script.ps1 <== >> echo "Hello World!" >> Exit 1234 >> >> ==> script.py <== >> import subprocess >> p = subprocess.Popen(['powershell.exe', '-File', '.\\script.ps1']) >> p.wait() >> print "exit status =", p.returncode >> >> ============== >> >> The p.wait() is important: >> https://docs.python.org/2/library/subprocess.html?highlight=check_output#subprocess.Popen.wait >> >> Now ... >> >> PS here> java -jar "C:\Jython\2.7.1-sa\jython-standalone-2.7.1.jar" >> script.py >> Hello World! >> exit status = 1234 >> >> >> Jeff Allen >> On 13/08/2018 18:20, Peter O'Reilly via Jython-users wrote: >>> Error says, >>> AttributeError: 'module' objects\ has no attribute 'check_output' >>> >>> I need the \return code from this line, >>> pipe = subprocess.Popen(['powershell.exe', >>> 'MY_SCRIPT.ps1',stdout=sys.stdout] >>> >>> >>> >>> >>> Peter >>> >>> >> > -- > Thank you, > Peter O'Reilly |