Discussion:
run python script with arguments in wx.py
linuxNewBee
2014-09-30 17:14:01 UTC
Permalink
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.
--
You received this message because you are subscribed to the Google Groups "wxPython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to wxpython-users+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Nathan McCorkle
2014-09-30 23:24:19 UTC
Permalink
Post by linuxNewBee
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
wx.Panel.__init__(self, parent)
self.shell = PyShell(self, -1)
fileName = openFile(message = 'Please enter the script file name')
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.
runfile(*self*, *filename*)¶
<http://wxpython.org/Phoenix/docs/html/py.shell.Shell.html#py.shell.Shell.runfile>
"Execute all commands in file as if they were typed into the shell."
--
You received this message because you are subscribed to the Google Groups "wxPython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to wxpython-users+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
linuxNewBee
2014-10-01 11:29:12 UTC
Permalink
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.
--
You received this message because you are subscribed to the Google Groups "wxPython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to wxpython-users+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Nathan McCorkle
2014-10-01 16:54:58 UTC
Permalink
Post by linuxNewBee
so it there any other way to execute python script with arguments?
I use subprocess.Popen
--
You received this message because you are subscribed to the Google Groups "wxPython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to wxpython-users+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Charles J. Daniels
2014-10-01 17:05:35 UTC
Permalink
Post by linuxNewBee
so it there any other way to execute python script with arguments?
--
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.call :
https://docs.python.org/2/library/subprocess.html#module-subprocess

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.
--
You received this message because you are subscribed to the Google Groups "wxPython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to wxpython-users+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
linuxNewBee
2014-10-07 01:41:51 UTC
Permalink
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.
--
You received this message because you are subscribed to the Google Groups "wxPython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to wxpython-users+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Loading...