[Tutor] Windows Linux Popen
eryksun
eryksun at gmail.com
Thu Jun 27 18:50:49 CEST 2013
On Thu, Jun 27, 2013 at 11:32 AM, Matthew Ngaha <chigga101 at gmail.com> wrote:
> On Thu, Jun 27, 2013 at 1:41 PM, eryksun <eryksun at gmail.com> wrote:
>
>> The error is telling you that Windows can't find "python3". The exe is
>> named python.exe on Windows, not python3.exe, and it will have to be
>> on your system PATH to be invoked like that. If you want to run the
>> script with the current interpreter, you can use sys.executable. For
>> example:
>>
>> >>> subprocess.Popen(
>> ... [sys.executable, '-c', r'print("spam")']).wait()
>> spam
>> 0
>
> i really don't know what to say. no one on irc could resolve my issue
> and in 1 go you spot where i went wrong. The small change of making
> 'python3', 'python' has fixed the issue. Thanks you very much:)
Actually, the part about python.exe needing to be on system PATH isn't
correct. On Windows, Popen uses CreateProcess, and I forgot that this
searches the application directory first. Here's the complete search
order:
The directory from which the application loaded.
The current directory for the parent process.
The 32-bit Windows system directory.
The 16-bit Windows system directory.
The Windows directory.
The directories that are listed in the PATH environment variable.
This assume you aren't using the "executable" argument of Popen. The
latter maps to the lpApplicationName argument of CreateProcess:
The string can specify the full path and file name of the module
to execute or it can specify a partial name. In the case of a
partial name, the function uses the current drive and current
directory to complete the specification. The function will not
use the search path. This parameter must include the file name
extension; no default extension is assumed.
sys.executable works here, also.
source:
http://msdn.microsoft.com/en-us/library/ms682425
More information about the Tutor
mailing list