#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2013
    Posts
    2
    Rep Power
    0

    Some help with subprocess.call


    Hi,

    I'm totaly new to python and I'm struggling with a subprocess.call. I have a little form that lets the user inputs the length of seconds for a video. Once the users presses the button the python script should call a shell script like:

    Code:
    /home/pi/Scripts/sec=10 ./take_video
    the shell command works on its own.

    My questions is now how to write the subprocess call correctly including the variable vid_time read from the user input field.

    Code:
    # Click on Button Take Video      
    	def onvidclick(self):
    		vid_time = self.txt.get_text()
    		subprocess.call(['/home/pi/Scripts/sec=' + vid_time + ' ./take_video'])
    		ts = time.time()
    		localtime = datetime.datetime.fromtimestamp(ts).strftime('%Y-%m-%d %H:%M:%S')
    		button_text = "Took a video at: " + localtime
    		self.title.set_text(button_text)
    Help would be welcomed.

    Cheers,

    Holger
  2. #2
  3. Contributing User
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Aug 2011
    Posts
    4,891
    Rep Power
    481
    Code:
    subprocess.call('/home/pi/Scripts/sec=' + vid_time + ' ./take_video', shell=True)
    subprocess.call(['/home/pi/Scripts/sec=' + vid_time, ' ./take_video'])
    Either of these should work.

    Do you really truly have programs named for every possible vid_time ? I suppose you might, depending on the cleverness of self.txt.get_text()
    [code]Code tags[/code] are essential for python code and Makefiles!
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2013
    Posts
    2
    Rep Power
    0
    Originally Posted by b49P23TIvg
    Code:
    subprocess.call('/home/pi/Scripts/sec=' + vid_time + ' ./take_video', shell=True)
    subprocess.call(['/home/pi/Scripts/sec=' + vid_time, ' ./take_video'])
    Either of these should work.

    Do you really truly have programs named for every possible vid_time ? I suppose you might, depending on the cleverness of self.txt.get_text()
    Thanks for the qujick reply. On the end I changed the script a bit. It now runs like this.

    Code:
    /home/pi/Scripts/./take_video2 10
    the subprocess call looks like this.

    Code:
    subprocess.call(['/home/pi/Scripts/./take_video2', self.txt.get_text()])
    the user can enter any number which will record videos in seconds. above call will record a video of 10 seconds.

    Works now. Thanks.

IMN logo majestic logo threadwatch logo seochat tools logo