First check your slashes... they should be forward slashes for Linux (Windows will work with either btw).
Second... if you do not pass the command with "shell=True" when using subprocess module, then the command must be passed in as a list instead of a string (if the command has multiple options etc. they must be broken into individual elements). In your case it's easy... there's no spaces in your command so it will be a 1 element list.
Also since you're using Popen, I'm assuming you want the output of the command? Don't forget to decode() the output to a string from a binary string.
Here is an example:
james@VIII:~/NetBeansProjects/Factorial$ ls
factorial.c factorial.exe
james@VIII:~/NetBeansProjects/Factorial$ ./factorial.exe
5
120
james@VIII:~/NetBeansProjects/Factorial$ /home/james/NetBeansProjects/Factorial/factorial.exe
5
120
james@VIII:~/NetBeansProjects/Factorial$
james@VIII:~/NetBeansProjects/Factorial$ python3
Python 3.6.7 (default, Oct 22 2018, 11:32:17)
[GCC 8.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from subprocess import Popen, PIPE
>>> cmd = ["/home/james/NetBeansProjects/Factorial/factorial.exe"]
>>> output = Popen(cmd, stdout=PIPE).communicate()[0].decode()
>>> output
'5\n120\n'
>>> output.strip().split()
['5', '120']
This is assuming your exe will really run on Linux. I just named that factorial.exe for the sake of clarity and for answering your question. Typically on Linux you won't see a file named factorial.exe
... it would just be factorial
.
If you really want to pass the command as a string for some reason. You need the shell=True
parameter:
>>> from subprocess import Popen, PIPE
>>> cmd = "/home/james/NetBeansProjects/Factorial/factorial.exe"
>>> output = Popen(cmd, stdout=PIPE, shell=True).communicate()[0].decode().strip().split()
>>> output
['5', '120']
You could also do this with the os module too... frowned upon by some in the community, but much cleaner in my opinion (and less code):
>>> from os import popen
>>> cmd = "/home/james/NetBeansProjects/Factorial/factorial.exe"
>>> out = [i.strip() for i in popen(cmd)]
>>> out
['5', '120']