Python script to run shell command
I'm having a bit of trouble. I want to run a shell command within Python
in a specific directory. Based on the code I found on the internet I need
the following inclusions:
import os
import subprocess
import shlex
And then the code itself is below
os.chdir('/etc/test/')
cmd = 'scrapy crawl test'
subprocess.call(shlex.split(cmd))
As it looks like, I am trying to run the command "scrapy crawl test"
within the /etc/test/ directory. When I run this manually with terminal it
seems to work fine however when I run it with this python code it gives me
an error number 2 relating to a directory error.
Is anyone able to tell me if my code is incorrect, or if I am going about
this the wrong way perhaps.
No comments:
Post a Comment