[Tutor] pass argument from python to powershell

Alan Gauld alan.gauld at btinternet.com
Sat Dec 14 16:18:52 CET 2013


On 14/12/13 12:57, phanidhar wrote:

> Have a code which is powershell script and i want to execute this script
> using python .
>
> example of powershell script content is :
>
> get-aduser $args[0]
>
> Python script :
>
> import subprocess
> import os
>
> a =
> subprocess.Popen([r'C:\WINDOWS\system32\WindowsPowerShell\v1.0\powershell.exe',
> './aduser.ps1'])
> result = a.wait()
>
> so when i run the python script it displays all the output of AD users
> but not the argument alone i give.

You don't appear to be giving any arguments to the Powershell Script?
You are just calling

powershell.exe ./aduser.ps1

Where is the argument defined? Are you by any chance passing it
to the python script when you call it? If so you will need to,
like the powershell version, extract it from sys.srgv[] and then
pass it into the Popen call.


-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.flickr.com/photos/alangauldphotos



More information about the Tutor mailing list