os.system vs subrocess.call

Pieter van Oostrum pieter-l at vanoostrum.org
Thu Nov 28 06:30:27 EST 2019


Ulrich Goebel <ml at fam-goebel.de> writes:

> Hi,
>
> I have to call commands from inside a python skript. These commands are
> in fact other python scripts. So I made
>
>     os.system('\.Test.py')
>
> That works.

In a string \. is the same as . So this should execute the command '.Test.py'. Is that really what you did? Or did you mean os.system('./Test.py') which is much more probable.
NOTE: Never retype the commands that you used, but copy and paste them.

>
> Now I tried to use
>
>     supprocess.call(['.\', 'test.py'])
>
That can't have given the error below, as it would have to be subprocess.call,
not supprocess.call.
And then also '.\' would have given a syntax error.
NOTE: Never retype the commands that you used, but copy and paste them.

> That doesn't work but ends in an error:
>
> Traceback (most recent call last):
>   File "<stdin>", line 1, in <module>
>   File "/usr/lib/python3.5/subprocess.py", line 557, in call
>     with Popen(*popenargs, **kwargs) as p:
>   File "/usr/lib/python3.5/subprocess.py", line 947, in __init__
>     restore_signals, start_new_session)
>   File "/usr/lib/python3.5/subprocess.py", line 1551, in _execute_child
>     raise child_exception_type(errno_num, err_msg)
> PermissionError: [Errno 13] Permission denied
>
> Using
>
>     subprocess.call(['./', 'Test.py'], shell=True)
>
> I get
>
> Test.py: 1: Test.py: ./: Permission denied
>
Why would you do that, splitting './Test.py' in two parts? That doesn't work.
> Is there a simple way to use subprocess in this usecase?
>

subprocess.call(['./Test.py'])

-- 
Pieter van Oostrum
www: http://pieter.vanoostrum.org/
PGP key: [8DAE142BE17999C4]


More information about the Python-list mailing list