0

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
OR
/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"
 19
 21
 22 getCreds()

How do I run this script from a remote directory ?

Thanks

1
  • Do you mean a remote computer, or just a different directory on the same computer? If it is a different directory on the same computer, then I would avoid calling it "remote" to avoid confusion Commented Nov 19, 2016 at 2:29

1 Answer 1

1

Use the cwd argument:

 p = subprocess.Popen("./3rdPartyScript -u %s -p %s -flag 123" % (access_key, secret_key), 
                      shell=True, 
                      stdout=subprocess.PIPE, 
                      cwd=YOUR_DIRECTORY)
Sign up to request clarification or add additional context in comments.

1 Comment

fantastic, Just curious if I was not using python to do this and I was doing it in bash is there a "cwd" like flag I could use?

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.