Re: Capturing a Return Code?

<[email protected]> Mon, 13 Aug 2018 14:37:57 -0600
Newsgroups gmane.comp.lang.jython.user
Message-ID <[email protected]>
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
<[email protected]> 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
>  [email protected] [3]
>  https://lists.sourceforge.net/lists/listinfo/jython-users [4]
>    
> 
> Links:
> ------
> [1] mailto:[email protected]
> [2] http://sdm.link/slashdot
> [3] mailto:[email protected]
> [4] https://lists.sourceforge.net/lists/listinfo/jython-users

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot