sanjay.sharma
sanjay.sharma

Reputation: 21

Python: I want to execute shell commands using python script

I want to execute shell command "objdump" using python for my research work I have used subprocess.call("command") to execute linux command but its not working.

Sample code which i have tried is

import subprocess
subprocess.call("date")

after the execution

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Python27\lib\subprocess.py", line 168, in call
    return Popen(*popenargs, **kwargs).wait()
  File "C:\Python27\lib\subprocess.py", line 390, in __init__
    errread, errwrite)
  File "C:\Python27\lib\subprocess.py", line 640, in _execute_child
    startupinfo)
WindowsError: [Error 2] The system cannot find the file specified

Upvotes: 1

Views: 1131

Answers (2)

RaminNietzsche
RaminNietzsche

Reputation: 2791

You must do this:

subprocess.call('date', shell=True)

Actually, Shell does allow you to access to global variable and programs that are in $PATH and your shell.

Upvotes: 3

Guillaume GAUTREAU
Guillaume GAUTREAU

Reputation: 1

Have you tried ?

import subprocess
subprocess.call("date", shell = True)

Upvotes: 0

Related Questions