run python script with arguments in wx.py

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.

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(self, filename)
“Execute all commands in file as if they were typed into the shell.”

···

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)

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
Sent from the wxPython-users mailing list archive at Nabble.com.

I use subprocess.Popen

···

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.call : 17.1. subprocess — Subprocess management — Python 2.7.18 documentation

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.

···

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?

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

Sent from the wxPython-users mailing list archive at Nabble.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: http://wxpython-users.1045709.n5.nabble.com/run-python-script-with-arguments-in-wx-py-tp5722693p5722744.html
Sent from the wxPython-users mailing list archive at Nabble.com.