2

I am attempting to pass 2 arguments to a python script via Powershell.

CODE:

$env:PATHEXT += ";.py"

[Environment]::SetEnvironmentVariable("Path", "$env:Path;c:\Program Files\lcpython15\", "User") 

$args1 = "Test1"
$args2 = "Test2"
$Python_SetAttrib = "c:\ProgramData\set_cust_attr.py "

python $Python_SetAttrib $args1 $args2

USAGE FROM CMD.exe: 
c:\ProgramData\set_cust_attr.py <custom attribute name> <custom attribute value>

ERROR:

PS C:\ProgramData> python $Python_SetAttrib + $args1 +  $args2
usage: c:\ProgramData\set_cust_attr.sh <custom attribute name> <custom attribute value>
OR
usage: c:\ProgramData\Opsware\set_cust_attr.sh --valuefile <path to file with value     in     it> <custom attribute name>

python.exe : Got more than one custom attribute name.
At line:1 char:7
+ python <<<<  $Python_SetAttrib + $args1 +  $args2
    + CategoryInfo          : NotSpecified: (Got more than one custom attribute     name.:String) [], RemoteException
    + FullyQualifiedErrorId : NativeCommandError

Unhandled exception in thread started by 
Traceback (most recent call last):
  File ".\client\__init__.py", line 88, in pumpthread
  File "C:\Program Files\lcpython15\lib\site-packages\pythoncom.py", line 3, in ?
    pywintypes.__import_pywin32_system_module__("pythoncom", globals())
  File "C:\Program Files\lcpython15\Lib\site-packages\win32\lib\pywintypes.py", line     68, in __import_pywin32_system_module__
    import _win32sysloader
ImportError: No module named _win32sysloader
7
  • Judging from the error message, the issue seems to be with your Python code, not with your PowerShell code. Commented Jul 2, 2013 at 12:34
  • Why are you using the + operator between the parameters (python $Python_SetAttrib + $args1 + $args2)? Do you want to concatenate the arguments (if so, you'd need to surround them with parens, ($Python_SetAttrib + $args1 + $args2))? If not, I don't know what you mean. If you mean for them to be separate parameters to the python script, then you wouldn't need + at all. Commented Jul 2, 2013 at 13:44
  • When I pass the parameters via ( ) it gives me : " Unexpected token 'args1' in expression or statement." Commented Jul 2, 2013 at 15:39
  • Currently there is a .bat to run python and the script. So, it would works if I run (at cmd line) : attrib.bat <arg1> <arg2> The .bat just contains : : python.exe <python script.py> I'm trying to not use the .bat file by calling: python.exe <python script> <arg1> <arg2> Commented Jul 2, 2013 at 15:43
  • For clarity: python c:\ProgramData\set_cust_attr.py + $args1 + $args2 calls set_cust_attr.py with 4 arguments: +, $args1, + and $args2. Commented Jul 2, 2013 at 21:28

1 Answer 1

1

Got it! Darn single quotes.....

$env:Path += ";c:\Program Files\lcpython15";
$env:PATHEXT += ";.py"; 
$arg1 = "Test3" 
$arg2 = "Testing" 
$arg3 = 'c:\ProgramData\set_cust_attr.py' 
python $arg3 $arg1 $arg2    
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.