Python script not calling script parameters correctly?

jrogersnh
New Contributor III

I have a python script that has values in $4 and $5. Currently, the $4 is getting called fine and working without issue, however I can't get $5 to work at all, it just never is evaluated and returns the literal string of "$5" instead of the value. I've tried setting it to a variable, using sys.argv[5], etc and I can't seem to get it to work.. Anyone ever run into a similar issue?

1 ACCEPTED SOLUTION

sdagley
Esteemed Contributor II

@jrogersnh sys.argv[parameter#] should work to get the script parameters in Python. The thread Adding a Python Script to JSS might have useful info.

View solution in original post

4 REPLIES 4

jrogersnh
New Contributor III

an example in my code would be:

command = "<command goes here>" + "$5"

if os.path.exists("<filepath>"): subprocess.call(command, shell=True)

The issue is the command I'm trying to call continues to use $5 as that literal string so it isn't working, although it works just a few lines up in my script with parameter $4.

sdagley
Esteemed Contributor II

@jrogersnh sys.argv[parameter#] should work to get the script parameters in Python. The thread Adding a Python Script to JSS might have useful info.

jrogersnh
New Contributor III

Thanks for the response!

I have tried this and to no luck.. Are there any characters that aren't allowed in the parameter fields? I've tested sys.argv[3] and that returns the correct username, however if I change it to sys.argv[5] it then returns an empty string. I have confirmed that I'm not a complete moron, and parameter field 5 is the correct parameter and it is filled with actual data :)

jrogersnh
New Contributor III

Looks like I figured it out now - seems to be an issue with the command itself I was running, however I have no clue why it was returning a blank field when I was checking the values haha. Either way, I've got it working and can confirm that sys.argv[5] is the way to go :) Thanks for the help!