Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python cmd stop terminal from showing stderr or stdout

Original Title: Python cmd stop terminal from showing running lines

I could not research this as well as I usually do because I am not sure of the proper terminology to describe what I am trying to stop.(The answer turns out to be stderr)

I have written a small python program that runs files in their native software. I am using Linux so the command is

opener ="open" if sys.platform == "darwin" else "xdg-open" subprocess.call([opener, winner])

where winner is the file path to be opened. As an interface, I am using the CMD package. Everything runs fine and as expected.

The problem I have is in the terminal. This is where I am unsure what to call it. After the subprocess.call is ran, the terminal shows what it is doing to open the file. It ends up being about 60 lines depending on what it is opening.

I have three questions:

  1. What do you call the terminal lines for it processing a file opening?

  2. How do I stop these lines from showing up. I do not need specific code, just a direction to go. I realize that there may be no way to do this from python, but I hope there is.

  3. This is a generic question about python packages. The cmd docs says that this is "useful for test harnesses, administrative tools, and prototypes that will later be wrapped in a more sophisticated interface." But it gives no other interface options. Have I met the limitations of cmd? And if so, what command line interface package should I use to solve this problem. (Unfortunately, I do not think I am good enough with python yet to make a full blown gui)

def start_winner(lst): #starts a file link or a random one from a list winner=random.choice(lst) opener ="open" if sys.platform == "darwin" else "xdg-open" subprocess.call([opener, winner])

like image 434
lost Avatar asked Mar 24 '26 08:03

lost


1 Answers

This answer is 100% @PadraicCunningham. If he post an answer, up vote his instead.

The answer to the questions:

1) The command output was the stderr (could have easily been the stdout). If you are unsure of the difference, wiki and link

2) I changed my start function to

def start_winner(lst): #starts a file link or a random one from a list winner=random.choice(lst) f=open(os.devnull,"w") opener ="open" if sys.platform == "darwin" else "xdg-open" subprocess.call([opener, winner], stdout=f, stderr=f)

3) No, CMD was not the problem, my lack of understanding outputs was.

like image 114
lost Avatar answered Mar 26 '26 21:03

lost



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!