0

I have a script.py in /Users/admin/Desktop and I want to run this script on a file that is in /Users/admin//Desktop/folder/file.txt, without changing the present dir.

Question: what is the most efficient way to do that on command-line ? I am using the following commands and results are not as expected.

$ python script.py --script; /Users/admin/Desktop/file.txt

     raise StopIteration('because of missing file (file.txt)')

 StopIteration: because of missing file (file.txt)
5
  • 1
    1) The semicolon will prematurely terminate the command. 2) You don't show your code. Commented Aug 4, 2016 at 10:42
  • 1
    Possible duplicate of Temporarily change current working directory in bash to run a command Commented Aug 4, 2016 at 10:43
  • I have 2000 lines long code! Commented Aug 4, 2016 at 10:43
  • Did you consider pass as an argument to the script the path of file.txt? Commented Aug 4, 2016 at 10:45
  • @user3698773: post only the code relevant to the problem. See stackoverflow.com/help/mcve Commented Aug 4, 2016 at 10:53

1 Answer 1

1
  1. Remove the semicolon because that will prematurely terminate the command.
  2. Pass the correct path to the file to your program. You say it is /Users/admin/Desktop/folder/file.txt, however, your command is using /Users/admin/Desktop/file.txt (it's missing folder)

So the command should (probably) be:

$ python script.py --script /Users/admin/Desktop/folder/file.txt

If that doesn't work you will need to edit your question to show your code.

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.