0

If I have a command line like this:

abc -c config.json| xyz -c test.json

How can I run it in Python file? I mean we will don't type "abc -c config.json| xyz -c test.json" in the terminal. xyz and abc are applications that I have written.

So, May I have a help?

2 Answers 2

3

You can use this

os.system("abc -c config.json| xyz -c test.json")

This is like running abc -c config.json| xyz -c test.json in command prompt.

Sign up to request clarification or add additional context in comments.

Comments

1

Im a little confused by your question.

If you want to make a system call from within python you would use the subprocess module

x = subprocess.Popen("ls /home", shell=True, stdout=subprocess.PIPE).stdout.read()

If you want to run a python command from the command line you can either write it to a file and execute

python myFile.py

Or, run the commands directly to python

python -c "print("testing")"

7 Comments

Sorry, I just updated my question. Yes, I know subprocess, but how can I run the with the command line like this: abc -c config.json| xyz -c test.json.
I tried: subprocess.Popen(shlex.split("abc -c config.json| xyz -c test.json"), stdin=subprocess.PIPE, stdout=subprocess.PIPE) But It's not work for me.
what is "abc" and what is "xyz"? are these applications that you have written?
Yes, these are applications that I have written, @samson4649.
why are you using "shlex.split() ? you should be able to run -> subprocess.Popen( "abc -c config.json| xyz -c test.json", stdin=subprocess.PIPE, stdout=subprocess.PIPE)
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.