Home > Enterprise >  Excecuting command in command line (windows) with python
Excecuting command in command line (windows) with python

Time:09-24

I`m trying to execute the following command, which works well when inserting it directly to command line, with a python-script.

cd C:/xdltest & xdltest -line BC01 -port 20514 -wname :e:pr:APC_CV03_SW2:out 42.6

this code navigates to a folder with a program to write a value back to a process-control system.

but when trying to execute the exact same command with python-script using subprocess.run() I`m failling

to_process = 'xdltest -line BC01 -port 20514 -wname :e:pr:APC_CV03_SW2:out {}'.format(round(float(prediction_porosity),2))
subprocess.run(["cd", "C:/xdltest", "&", to_process],shell=True, stdin=subprocess.PIPE)

What is my failure?

[sucessfull completed command directly in cmd 1

command excecuted with python, but not sucessfull

CodePudding user response:

If you use the OS library, you should be able to circumvent the problem. Here is a link to some info. Good luck :)

CodePudding user response:

The command line (no python) screenshot does not show the actual exit code. Call "echo %errorlevel%" in the console afterwards to see it. Maybe it is also non zero here.

  • Related