A
A
Azat20152022-04-17 17:25:06
Python
Azat2015, 2022-04-17 17:25:06

How to pass input to the command line in python when starting an external application?

How to make the code work

cmd = "my_data | app.exe -p1 -p2 -p3 "
run_cmd = subprocess.Popen(cmd)

If I run the command "my_data | app.exe -p1 -p2 -p3" on the command line, everything works.
If I run from python with cmd = "app.exe -p1 -p2 -p3", i.e. without entering data, everything works too
When trying to run from python as in the above code, the error "FileNotFoundError: [WinError 2] Cannot find the specified file" appears.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
soremix, 2022-04-17
@Azat2015

subprocess.run('my_data | app.exe -p1 -p2 -p3', shell=True)

F
Flexonimus, 2022-04-17
@Flexonimus

Try

subprocess.run(Твоя команда, shell=True) #не возвращает вывод командной строки
subprocess.getoutput(Твоя команда, shell=True) #возвращает вывод командной строки.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question