Using wx.execute

As a totally newbie, I’ve unsuccessfully tried to execute this example:

#!/usr/bin/env python
# -*- coding: utf-8 -*-
import wx

if __name__ == '__main__':
    app = wx.App(False) 
    pid = wx.Execute('echo S', wx.EXEC_ASYNC)
    print(pid) 

It returns pid = 0. I am using Python 3.7.5 with wxPython 4.1.0 on Windows 10. What am I missing?

Thanks in advance.

Platform and version?

Is echo an actual executable on your system, or just a command built-in to the shell program? If the latter then you would need to construct a command that runs the shell executable and passes the command line you want to execute to it as CLI parameters.

Have you looked at the Process sample in the demo?

Finally, in almost all cases using Python’s subprocess module will probably be at least a good enough solution, if not better that using wx.Process/wx.Execute.

Hi, I am using Python 3.7.5 with wxPython 4.1.0 on Windows 10. “echo” is a builtin command of the Command Window (it behaves as print).

I didn’t use Process because I wanted to show here the simplest case possible (and yet valid).

Finally, regarding subprocess, the main goal is to adapt a very long program written in Python 2 and old wx 2.8, to Python 3 and new wx. I would like to change as few parts as possible to avoid unwanted side effects in a code that I do not fully understand.

I never noticed wx.Execute before… how cute!.. you learn something every day, I guess.

Anyways, “echo” is not a program in Windows, but a simple shell command. So you have to execute it through the shell, of course.

>>> import wx
>>> app = wx.App()
>>> wx.Execute('echo hello')
0
>>> wx.Execute('cmd /c echo hello')
14852
hello

The same applies to “dir”, “cd”, “set” and all the others shell commands. On the other hand, if you have the name (absolute/relative path, or just the name, really, if it is already in your system path) of a real executable program…

>>> wx.Execute('calc')  # this will open calc.exe
8628

The same would apply to Python’s subprocess, of course. Shell commands can be executed only by a shell instance.

1 Like

Thanks, that solved the problem.

Hi Robin et al,

sorry for hijacking this thread.

Is there a way to post a new topic via e-mail ?

If so, how to do so ?

Thanks,
Karsten

I have no idea. Since this system is based on Discourse, maybe they can answer that in Twitter: https://twitter.com/discourse.

Yes. If I set things up correctly, you should be able to send a message to {category-name}@wxpython.org, like newbie-help@wxpython.org. The message needs to be from the email address that is registered in your account here. Also, IIRC, the incoming email mailboxes are polled every five minutes, and the system is more aggressive on flagging messages that need moderator approval when they come from email, so messages may not end up on the site right away.

Hi Robin,

many thanks,

Yes. If I set things up correctly, you should be able to send a message to {category-name}@wxpython.org, like newbie-help@wxpython.org. The message needs to be from the email address that is registered in your account here. Also, IIRC, the incoming email mailboxes are polled every five minutes, and the system is more aggressive on flagging messages that need moderator approval when they come from email, so messages may not end up on the site right away.

I tried doing so with

generic-drop-target@wxpython.org

and we’ll see what happens :slight_smile:

Karsten

Sorry, by {category-name} I meant the list of discussion categories you can see on the left side of this page: https://discuss.wxpython.org/categories. Discourse uses the term “Topic” for the individual message threads in the categories. The email subject should be used as the topic when the message is imported.

Sorry, by {category-name} I meant the list of discussion
categories you can see on the left side of this page:
https://discuss.wxpython.org/categories. Discourse uses the
term “Topic” for the individual message threads in the
categories. The email subject should be used as the topic
when the message is imported.

Hi Robin,

thanks for the explanation. I tried, but got this:

Got what? (It looks like you clicked send/reply too soon.)

Got what? (It looks like you clicked send/reply too soon.)

This:

Yep, it looks like Discourse is truncating the message, probably because the quoted portion includes the email headers and so it’s guessing that it is the end of the incoming message. I was able to access the original incoming email, for the record here is the relevant text:

	We're sorry, but your email message to ["wxpython-users@wxpython.org"] 
	(titled test) didn't work.

	Your account does not have the required trust level to post new topics to 
	this email address. If you believe this is an error, [contact a staff member]
	(https://discuss.wxpython.org/about).

So it’s basically part of the spam protection functionality. There are a bunch of site interaction metrics which will automatically bump you up from level 1 (basic user) to level 2 (member) but If you are mostly using just email then you will likely not ever trigger that bump. (The metrics are things like number of minutes reading posts, number of days active on the site, number of topics read, likes given and received, etc.)

I’ll go ahead and manually set your trust level since I’m pretty sure that you are not a bot :wink: so it should work for you now.

Brilliant, thanks heaps :slight_smile:

Will test.

Karsten