Question: (Closed) command line python script run on a file in different directory
0
gravatar for ahmedakhokhar
2.7 years ago by
ahmedakhokhar110
Belgium
ahmedakhokhar110 wrote:

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 path (i.e. /Users/admin/Desktop)

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)

so far I have tried the following commands:

Fail #1:

python script.py  && /Users/admin/Desktop/folder/file.txt
StopIteration: because of missing file (file.txt)

Fail #2

python script.py;  /Users/admin/Desktop/folder/file.txt
StopIteration: because of missing file (file.txt)

Fail #3

python script.py -C ~/Users/admin/Desktop/folder/file.txt
StopIteration: because of missing file (file.txt)
python • 4.7k views
ADD COMMENTlink modified 2.7 years ago by Devon Ryan89k • written 2.7 years ago by ahmedakhokhar110
1

This is clearly not a problem of different directories between your file and the script, but mostly because you don't understand how scripts (and probably unix system) works.

I suggest you to first read some unix tutorial and come here again with real bioinformatics question.

ADD REPLYlink written 2.7 years ago by Rob90
1

Hello ahmedakhokhar!

We believe that this post does not fit the main topic of this site.

This is not a bioinformatics question. Please google/search stack overflow.

For this reason we have closed your question. This allows us to keep the site focused on the topics that the community can help with.

If you disagree please tell us why in a reply below, we'll be happy to talk about it.

Cheers!

ADD REPLYlink written 2.7 years ago by RamRS21k

Did you try python script.py /Users/admin/Desktop/file.txt? Should work if the script is written in such a way that it can parse the file path you are providing. If the script expects the file to be in the local directory then you could make a soft link to the file locally and see if that works. I assume you are asking this because you are not able to modify the script yourself.

ADD REPLYlink modified 2.7 years ago • written 2.7 years ago by genomax65k

Your attempts #1 and #2 certainly failed because you are running first script.py without arguments and then you try to run /Users/admin/Desktop/folder/file.txt on its own, which probably makes no sense. This is because you have ; or && separating script.py and the input.

ADD REPLYlink written 2.7 years ago by dariober10.0k

It would help us if you would show us the content of the script. Most likely what genomax2 and Devon Ryan described will work. It's rather bad practice to name your script 'script.py', so I hope that's not the real name. If that script always has to work on the same file you could hard-code it in the script so you don't have to specify it on the command line.

This is not really a bioinformatics question so this might get closed.

ADD REPLYlink written 2.7 years ago by WouterDeCoster38k
0
gravatar for Devon Ryan
2.7 years ago by
Devon Ryan89k
Freiburg, Germany
Devon Ryan89k wrote:

The most efficient way is either:

python script.py folder/file.txt

or

./script.py folder/file.txt

BTW, this is incredibly off-topic.

ADD COMMENTlink written 2.7 years ago by Devon Ryan89k
Please log in to add an answer.
The thread is closed. No new answers may be added.

Help
Access

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 2.3.0
Traffic: 1228 users visited in the last hour