0

I'm trying to create a program that will launch livestreamer.exe with flags (-example), but cannot figure out how to do so.

When using the built in "run" function with windows, I type this: livestreamer.exe twitch.tv/streamer best

And here is my python code so far:

import os

streamer=input("Streamer (full name): ")
quality=input("""Quality:
Best
High
Medium
Low
Mobile
: """).lower()
os.chdir("C:\Program Files (x86)\Livestreamer")
os.startfile("livestreamer.exe twitch.tv "+streamer+" "+quality)

I understand that the code is looking for a file not named livestreamer.exe (FileNotFoundError), but one with all the other code put in. Does anyone know how to launch the program with the arguments built in? Thanks.

Frozone
  • 13
  • 1
  • 4

2 Answers2

0

How about subprocess.call? Something like:

import subprocess
subprocess.call(["livestreamer.exe", "streamer", "best"])
YS-L
  • 14,358
  • 3
  • 47
  • 58
  • Thanks for the comment, however I wasn't exactly sure how to get this one to work, whereas Azwr's up above worked straight away and hid the cmd.exe that opened in the background. – Frozone Jan 25 '14 at 15:56
0

Use os.system() instead of os.file(). There is no file named "livestreamer.exe twitch.tv "+streamer+" "+quality

Also , os.system() is discouraged , use subprocess.Popen() instead. Subprocess.Popen() syntax looks more complicated, but it's better because once you know subprocess.Popen(), you don't need anything else. subprocess.Popen() replaces several other tools (os.system() is just one of those) that were scattered throughout three other Python modules.

If it helps, think of subprocess.Popen() as a very flexible os.system(). An example :

sts = os.system("mycmd" + " myarg")

does the same with :

sts = Popen("mycmd" + " myarg", shell=True).wait()

OR

sts = Popen("mycmd" + " myarg", shell=True)
sts.wait()

Source : Subprocess.Popen and os.system()

Community
  • 1
  • 1
Azwr
  • 774
  • 8
  • 13
  • Thanks, got it working with your os.system("livestreamer.exe twitch.tv/"+streamer+" "+quality"). I'll work with the Popen function now and see if I can get it to work. What does the .wait thing do? Is it necessary to include? – Frozone Jan 25 '14 at 15:54
  • `wait()` waits for Popen process to finish , read more at http://docs.python.org/release/2.6.5/library/subprocess.html – Azwr Jan 25 '14 at 15:59
  • I see, so say for example if I entered a streamer who wasn't streaming and the command file didn't open, would any code that I type after the .wait function run straight away? I'm thinking this would be good to implement for broad networks that have more than one channels on twitch. – Frozone Jan 25 '14 at 16:01
  • Why don't you try doing this by yourself ;-) ? Also consider reading 18.1.2. on http://docs.python.org/release/2.6.5/library/subprocess.html – Azwr Jan 25 '14 at 16:05