chowpay chowpay - 1 year ago 69
Bash Question

python executing a remote script in a different directory

Wrote python script to execute below after prompting for a username and password

./3rdpartyscript -u username -p password -flag 123

It works fine but the "3rdpartyscript" has a bunch of files it relies on and I didnt want to clutter the root directory so I moved everything into a folder. I also have no access to actually manipulate the script, only run it.

I can't get this to run correctly:

./folder/3rdpartyscript -u username -p password -flag 123
/folder/3rdpartyscript -u username -p password -flag 123

I'm also taking the results of this script and using it for other things.

here's what I have so far:

6 def getCreds():
7 global access_key, secret_key, yourName
8 access_key = raw_input("Enter User Name: ")
9 secret_key = raw_input("Enter Password: ")
10 infoCorrect = raw_input('Is this information correct? (y or n)')
11 if infoCorrect.lower() == "yes" or infoCorrect.lower() =="y":
12 p = subprocess.Popen("./3rdPartyScript -u %s -p %s -flag 123" % (access_key, secret_key), shell=True, stdout = subprocess.PIPE)
13 output,err = p.communicate()
14 print(output)

I'll take the result of "output" and eventually put it against some kinda decision.

17 else:
18 print "\n Couldn't connect to please check your credentials \n"
22 getCreds()

How do I run this script from a remote directory ?


Answer Source

Use the cwd argument:

 p = subprocess.Popen("./3rdPartyScript -u %s -p %s -flag 123" % (access_key, secret_key), 
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download