Why subprocess.call () is showing error in linux?
Question: Let us consider Linux platform where I need to execute a program called
smart.exe which uses input.dat file. Both the files are placed in the same
directory with each file having the same file permission 777.

Now if I run the following command in the terminal window smart.exe is fully
executed without any error.

    
    
    $./smart.exe input.dat
    

On the other hand, if I use the following python script called my_script.py
placed in the same directory, then I get an error.

my_script.py has the following code:

    
    
    #!/usr/bin/python
    import os, subprocess
    
    exit_code = subprocess.call("./smart.exe input.dat", shell = False)
    

The error is as follows:

    
    
    File "my_script.py", line 4, in <module>
    exit_code = subprocess.call("./smart.exe input.dat", shell = False) 
    File "/usr/lib64/python2.6/subprocess.py", line 478, in call
    
    p = Popen(*popenargs, **kwargs)
    File "/usr/lib64/python2.6/subprocess.py", line 642, in __init__
        errread, errwrite)
    File "/usr/lib64/python2.6/subprocess.py", line 1234, in _execute_child
    raise child_exception
    OSError: [Errno 2] No such file or directory
    

Can someone please tell me why this is happening. Please note that the
smart.exe should take around 10 sec to fully complete. This may be a clue for
the problem.

Please also advise if there is any other way to run smart.exe from
my_script.py. Your solution is much appreciated!


Answer: You should decide if you want shell support or not.

If you want the shell to be used (which is not necessary here), you should use
`exit_code = subprocess.call("./smart.exe input.dat", shell=True)`. Then the
shell interprets your command line.

If you don't want it (as you don't need it and want to avoid unnecessary
complexity), you should do `exit_code = subprocess.call(["./smart.exe",
"input.dat"], shell=False)`.

(And there is no point naming your binarys `.exe` under Linux.)

