run python script with arguments in wx.py

306 views
Skip to first unread message

linuxNewBee

unread,
Sep 30, 2014, 1:14:05 PM9/30/14
to wxpytho...@googlegroups.com
Hello ,

I am using wx.py.shell for running python command and scripts till now so
far so good. Now I need to run python script with arguments. Can somebody
suggest me how to move forward.

from wx.py.shell import Shell as PyShell

class ConsoleFrame(wx.Panel):
def __init__(self, parent):
wx.Panel.__init__(self, parent)
self.shell = PyShell(self, -1)
def runScript(self):
fileName = openFile(message = 'Please enter the script file name')
if os.path.isfile(fileName):
self.shell.runfile(fileName)




--
View this message in context: http://wxpython-users.1045709.n5.nabble.com/run-python-script-with-arguments-in-wx-py-tp5722693.html
Sent from the wxPython-users mailing list archive at Nabble.com.

Nathan McCorkle

unread,
Sep 30, 2014, 7:24:20 PM9/30/14
to wxpytho...@googlegroups.com


On Tuesday, September 30, 2014 10:14:05 AM UTC-7, Hemadri Saxena wrote:
Hello ,

I am using wx.py.shell for running python command and scripts till now so
far so good. Now I need to run python script with arguments. Can somebody
suggest me how to move forward.

from wx.py.shell import Shell as PyShell

class ConsoleFrame(wx.Panel):    
     def __init__(self, parent):
         wx.Panel.__init__(self, parent)
         self.shell = PyShell(self, -1)  
    def runScript(self):
         fileName = openFile(message = 'Please enter the script file name')
              if  os.path.isfile(fileName):
                   self.shell.runfile(fileName)

Seems that runfile is just going through each line of the provided file and passing it to the run method... so it isn't actually running the file, it is executing each line in the file... therefore I don't think the main will get called, and therefore there will be no concept of argv.

From the docs:
runfile(selffilename)
"Execute all commands in file as if they were typed into the shell."

linuxNewBee

unread,
Oct 1, 2014, 7:29:16 AM10/1/14
to wxpytho...@googlegroups.com
so it there any other way to execute python script with arguments?



--
View this message in context: http://wxpython-users.1045709.n5.nabble.com/run-python-script-with-arguments-in-wx-py-tp5722693p5722700.html

Nathan McCorkle

unread,
Oct 1, 2014, 12:54:58 PM10/1/14
to wxpytho...@googlegroups.com


On Wednesday, October 1, 2014 4:29:16 AM UTC-7, Hemadri Saxena wrote:
so it there any other way to execute python script with arguments?

I use subprocess.Popen


Charles J. Daniels

unread,
Oct 1, 2014, 1:05:36 PM10/1/14
to wxpytho...@googlegroups.com

It takes a list where the first item is the file to run, and the rest are arguments.

I also use os.exec*, but that replaces the current process, so not what you would want it seems.

linuxNewBee

unread,
Oct 6, 2014, 9:41:55 PM10/6/14
to wxpytho...@googlegroups.com
Hello,

class mycmder(wx.Frame):
    def __init__(self,cmd):
        wx.Frame.__init__(self, None, title="APT Command Execution", size=(600,400))           
        self.logArea = wx.TextCtrl(self, style=wx.TE_MULTILINE|wx.TE_READONLY)
        self.Logs = sessionLog()
        self.Show(True)
        self.execute_cmd(cmd)
            
    def execute_cmd(self,cmd):       
        myProcess = subprocess.Popen([cmd], stdout=subprocess.PIPE, stdin=subprocess.PIPE, stderr=subprocess.STDOUT, shell=True)
        command_ouput, _ = perlProcess.communicate()
        #Flushing 
        sys.stdout.flush()
        sys.stderr.flush()
        sys.stdin.flush()                
        self.logArea.SetValue(command_ouput)

When I use as  mycmder("runscript.py --config abc.cfg --script abc.py"), it launches a new window execute the command show me the output. without any error.

Now runscript.py execute the "abc.py script with parameter "abc.cfg". It has also debugging capability implemented in it that means when run the command "runscript.py --config abc.cfg --script abc.py" in terminal I can pause/resume/stop the execution. How can acheive the same in wxPython.




View this message in context: Re: run python script with arguments in wx.py
Reply all
Reply to author
Forward
0 new messages