Notice: This forum has been recovered from an old backup, so some content, links, and dates may be outdated. The forum is currently read-only while we restore sign-in and registration functionality. Details

If you find this forum valuable and would like to help keep it online, donations to help cover hosting and domain costs are greatly appreciated, but never expected. You can support the forum through Buy Me a Coffee or Ko-fi. Thank you for helping preserve the EventGhost community.

Python, Windows and the command line

If you have a question or need help, this is the place to be.
Post Reply
bixtool
Posts: 3
Joined: Mon Aug 15, 2011 9:19 pm

Python, Windows and the command line

Post by bixtool »

My last post disappeared. Here again:
Hi,
Great program. i've only discovered it recently, so i'm still learning.

i'm having problems running a windows program (therenamer) from the command line using a python script. The arguement string i'm sending to therenamer ( -ftech -ff="c:\xxx" -af="c:\yyy") appears to be formatted correctly by python, but it fails to work and only opens therenamer program as if no arguements were given.

Here is my code:

Code: Select all

import os
import subprocess

fetchfolder = "C:\\temp\\bones"
archivefolder = "C:\\smr"
args = '-fetch -ff="%s" -af="%s"' % (fetchfolder, archivefolder)
#args = '-fetch -ff="C:\\temp\\bones" -af="C:\\smr"' 
print args
try:
 retcode = subprocess.call(["C:\\Program Files (x86)\\theRenamer\\theRenamer.exe",args]) 

except:
 pass
Ive tried splitting the parameters:

Code: Select all

retcode = subprocess.call(["C:\\Program Files (x86)\\theRenamer\\theRenamer.exe", arg1, arg2, arg3]) 
Using os.system(xxx) failed.

Am I using the subprocess call corectly?
Can anyone suggest another Python process that will run a windows executable with commanmd line parameters?
User avatar
jitterjames
Experienced User
Posts: 677
Joined: Thu Aug 13, 2009 4:36 pm
Location: Quebec, Canada
Contact:

Re: Python, Windows and the command line

Post by jitterjames »

there is probably a way to do it in pure python but you can also do this:

Code: Select all

args = u'arg1 arg2 "and maybe arg3 in quotes"'
eg.plugins.System.Execute(u'C:\\Program Files (x86)\\theRenamer\\theRenamer.exe', args, 0, False, 2, u'C:\\Program Files (x86)\\theRenamer', False)
bixtool
Posts: 3
Joined: Mon Aug 15, 2011 9:19 pm

Re: Python, Windows and the command line

Post by bixtool »

Damn, that worked great. Thanks. It was soo frustrating. I had to modify your solution slightly to get it to work

Code: Select all

args = u'arg1 arg2 "and maybe arg3 in quotes"'
eg.plugins.System.Execute(u'C:\\Program Files (x86)\\theRenamer\\theRenamer.exe', args)
But it worked. I'm using it for two other windows programs as well.

Would you know if I can determine when the windows program I executed has closed/ended in Python? I'm using sleep timers to permit the windows program to finish before I execute other python commands. But this is inefficient. Sometimes therenamer completed in 20s other times it may take minutes.
User avatar
jitterjames
Experienced User
Posts: 677
Joined: Thu Aug 13, 2009 4:36 pm
Location: Quebec, Canada
Contact:

Re: Python, Windows and the command line

Post by jitterjames »

Yes, I think if you take my original example, and change false, to true it will wait until execution is finished. Eventghost will probably be frozen until that time though.
eatmeimadanish
Experienced User
Posts: 118
Joined: Thu Oct 01, 2009 5:11 pm

Re: Python, Windows and the command line

Post by eatmeimadanish »

You can also run subprocess.Popen to pass complete strings.
Post Reply