Python subprocess failed with "is not recognized as an internal or external command"

6 days ago 3
ARTICLE AD BOX

I would like to automate a task of running an application repeatedly with python subprocess.

1)The application is called "ltx" I have to run it with its argument "-h" e.g.

[~]$ltx -h

Note that I have already added the path into .bashrc so I can run it from any directory.

export PATH=$PATH:/home/joe/ltx/bin

This application has to run in linux terminal. In my case I use Cygwin64 Terminal. For example,

[~]$ ltx -h

[INFO] Startup arguments: [-h]

NAME .....

---> Showing the application run successfully

I try python automation with subprocess as below:

[~]$ python

Python 3.12.2 (tags/v3.12.2:6abddd9, Feb 6 2024, 21:26:36) [MSC v.1937 64 bit (AMD64)] on win32

Type "help", "copyright", "credits" or "license" for more information.

\>>> import subprocess

\>>> subprocess.run(['ls','-al'],shell=True) --> Test subprocess, working!

\>>> subprocess.run(['ltx','-h'],shell=True) --> Now, this is what I want. But error

'ltng-decoder' is not recognized as an internal or external command,

operable program or batch file.

CompletedProcess(args=['ltng-decoder', '-h'], returncode=1)

\>>> subprocess.run([r"C:\cygwin64\joe\ltx\bin\ltx","-h"],shell=True) -->Try this too, but still failed

'C:\cygwin64\home\joe\ltx\bin\ltx' is not recognized as an internal or external command,

operable program or batch file.

CompletedProcess(args=['C:\\cygwin64\\home\\joe\\ltx\\bin\\ltx', '-h'], returncode=1)

Could you suggest how to fix this or what to try next ? I would just like to see the subprocess can be run successfully with the "ltx -h". Much appreciated.
Read Entire Article