Skip to main content
Solved

Python script not calling script parameters correctly?


Forum|alt.badge.img+6

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?

Best answer by sdagley

@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 original
Did this topic help you find an answer to your question?

4 replies

Forum|alt.badge.img+6
  • Author
  • Contributor
  • 13 replies
  • April 15, 2019

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
Forum|alt.badge.img+25
  • Jamf Heroes
  • 3532 replies
  • Answer
  • April 15, 2019

@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.


Forum|alt.badge.img+6
  • Author
  • Contributor
  • 13 replies
  • April 15, 2019

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 :)


Forum|alt.badge.img+6
  • Author
  • Contributor
  • 13 replies
  • April 15, 2019

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!


Reply


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings