1

My program is a text editor for bash scripts. For the run option I need to obtain all the commands typed in the textbox and execute them as if they were an entire script (the option of writing the string in a file and then execute it is also possible). Also, I need to pass some arguments (a string in the entry box), and obtain stderr and stdout if the user wants it (checkboxes).

My program looks like this:

interface

I know how to obtain data from all graphic components, my big problem is that I'm not sure what to do: subprocess.call, subprocess.popen, os.system, etc. There are a lot of options. I need to use just one command whatever they write on the text box: pipes, simple commands, argument printing, etc.

It is desirable too that nothing is shown in my console.

Thank you for helping! Every idea is welcome!

I'm using Ubuntu.

1

1 Answer 1

2

Use subprocess. It was intended to replace other methods of running external processes. Rather than repeat the documentation, I will try to summarize:

In Python 2.7 you have several options:

subprocess.call : runs the command, returning the returncode

subprocess.check_call : raise exception if nonzero returncode is returned

subprocess.check_output : run command, returning output as a string

In Python 3.5+, the interface was simplified and you can simply use subprocess.run(), which returns a subprocess.CompletedProcess object from which you can access stdout, stderr, return code, etc.

https://docs.python.org/2.7/library/subprocess.html https://docs.python.org/3.6/library/subprocess.html

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

Comments

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.