Issuing a command via subprocess, other methods in Windows 7

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

Issuing a command via subprocess, other methods in Windows 7

David Hutto-2
Hi,

I'm using:

Microsoft Windows [Version 6.1.7600](Windows 7)
Copyright (c) 2009 Microsoft Corporation.  All rights reserved.

Python 2.6.6 (r266:84297, Aug 24 2010, 18:46:32) [MSC v.1500 32 bit (Intel)] on
win32

I've tried numerous methods trying to send a simple command in a shell session.

When the commands are placed into the windows command prompt directly,
they issue perfectly fine, but in the below interpreter session
errors, it finds and utilizes START, as well as other shell commands,
but not for other types of primary commands that work when typed
directly int the windows command prompt, such as SoundRecorder(shown
below).

Below are a few of my unlucky attempts:

>>> scope = subprocess.Popen(["SoundRecorder"],shell = True, stdout=subprocess.P
IPE)
>>>
>>> 'SoundRecorder' is not recognized as an internal or external command,
operable program or batch file.

>>> scope = os.system("START, SoundRecorder")

The system cannot find the file SoundRecorder.

>>> scope = subprocess.Popen([r'START', 'SoundRecorder'],shell = True, stdout=su
bprocess.PIPE)

>>> The system cannot find the file SoundRecorder.

scope = subprocess.Popen([r'START', 'C:\Windows\System32\SoundRecorder.exe'],she
ll = True, stdout=subprocess.PIPE)

>>> The system cannot find the file C:\Windows\System32\SoundRecorder.exe.

Just using START, like below:

scope = subprocess.Popen([r'START',shell =
 True, stdout=subprocess.PIPE)

initiates the START command, which means it works, but not on command
line when using SoundRecorder which is in the system32 dir. I thought
it might be a directory placement problem, but don't know if that
would be the correct way to fix it, or if that's even the problem.

Any ideas why the above works for the START, and not the
SoundRecorder, when both work on the windows command prompt when typed
directly in?


Thanks,
David
_______________________________________________
python-win32 mailing list
[hidden email]
http://mail.python.org/mailman/listinfo/python-win32
Reply | Threaded
Open this post in threaded view
|

Re: Issuing a command via subprocess, other methods in Windows 7

Preston Landers-2
I thought "start" wasn't an actual executable but rather a builtin
command of the cmd.exe shell.

Have you tried something like:

scope = subprocess.Popen([r'cmd.exe', '/c start SoundRecorder'],shell
= True, stdout=subprocess.PIPE)

regards,
Preston

On Wed, Feb 22, 2012 at 1:09 AM, David Hutto <[hidden email]> wrote:

> Hi,
>
> I'm using:
>
> Microsoft Windows [Version 6.1.7600](Windows 7)
> Copyright (c) 2009 Microsoft Corporation.  All rights reserved.
>
> Python 2.6.6 (r266:84297, Aug 24 2010, 18:46:32) [MSC v.1500 32 bit (Intel)] on
> win32
>
> I've tried numerous methods trying to send a simple command in a shell session.
>
> When the commands are placed into the windows command prompt directly,
> they issue perfectly fine, but in the below interpreter session
> errors, it finds and utilizes START, as well as other shell commands,
> but not for other types of primary commands that work when typed
> directly int the windows command prompt, such as SoundRecorder(shown
> below).
>
> Below are a few of my unlucky attempts:
>
>>>> scope = subprocess.Popen(["SoundRecorder"],shell = True, stdout=subprocess.P
> IPE)
>>>>
>>>> 'SoundRecorder' is not recognized as an internal or external command,
> operable program or batch file.
>
>>>> scope = os.system("START, SoundRecorder")
>
> The system cannot find the file SoundRecorder.
>
>>>> scope = subprocess.Popen([r'START', 'SoundRecorder'],shell = True, stdout=su
> bprocess.PIPE)
>
>>>> The system cannot find the file SoundRecorder.
>
> scope = subprocess.Popen([r'START', 'C:\Windows\System32\SoundRecorder.exe'],she
> ll = True, stdout=subprocess.PIPE)
>
>>>> The system cannot find the file C:\Windows\System32\SoundRecorder.exe.
>
> Just using START, like below:
>
> scope = subprocess.Popen([r'START',shell =
>  True, stdout=subprocess.PIPE)
>
> initiates the START command, which means it works, but not on command
> line when using SoundRecorder which is in the system32 dir. I thought
> it might be a directory placement problem, but don't know if that
> would be the correct way to fix it, or if that's even the problem.
>
> Any ideas why the above works for the START, and not the
> SoundRecorder, when both work on the windows command prompt when typed
> directly in?
>
>
> Thanks,
> David
> _______________________________________________
> python-win32 mailing list
> [hidden email]
> http://mail.python.org/mailman/listinfo/python-win32
_______________________________________________
python-win32 mailing list
[hidden email]
http://mail.python.org/mailman/listinfo/python-win32
Reply | Threaded
Open this post in threaded view
|

Re: Issuing a command via subprocess, other methods in Windows 7

Tim Roberts
In reply to this post by David Hutto-2
David Hutto wrote:
> initiates the START command, which means it works, but not on command
> line when using SoundRecorder which is in the system32 dir. I thought
> it might be a directory placement problem, but don't know if that
> would be the correct way to fix it, or if that's even the problem.
>
> Any ideas why the above works for the START, and not the
> SoundRecorder, when both work on the windows command prompt when typed
> directly in?

Yes.  The one critical piece of information you did not supply here is
that you are running 64-bit Windows 7.  That's the root of the problem.

SoundRecorder.exe is a 64-bit executable, and lives in
\Windows\System32.  When you are a 32-bit process on 64-bit Windows, and
you try to refer to files in \Windows\System32, the operating system
"helpfully" rewrites the path so you actually refer to
\Windows\SysWOW64, which is where the 32-bit executables and DLLs live.

Unlike almost every other utility, there is no 32-bit version of
SoundRecorder.exe, so subprocess fails to find the executable and dies.
Cmd.exe is a 64-bit process, so it looks in the real System32 and finds it.

So, what are your options?  One answer is to install a 64-bit build of
Python.  Another answer is to turn off the file system redirection using
ctypes.windll.kernel32.Wow64DisableWow64FsRedirection (I just tried it
-- it works).

By the way, there is no point in using Popen with SoundRecorder.  It's a
GUI application.  It doesn't use stdin and stdout.

--
Tim Roberts, [hidden email]
Providenza & Boekelheide, Inc.

_______________________________________________
python-win32 mailing list
[hidden email]
http://mail.python.org/mailman/listinfo/python-win32
Reply | Threaded
Open this post in threaded view
|

Re: Issuing a command via subprocess, other methods in Windows 7

David Hutto-2
On Wed, Feb 22, 2012 at 12:59 PM, Tim Roberts <[hidden email]> wrote:

> David Hutto wrote:
>> initiates the START command, which means it works, but not on command
>> line when using SoundRecorder which is in the system32 dir. I thought
>> it might be a directory placement problem, but don't know if that
>> would be the correct way to fix it, or if that's even the problem.
>>
>> Any ideas why the above works for the START, and not the
>> SoundRecorder, when both work on the windows command prompt when typed
>> directly in?
>
> Yes.  The one critical piece of information you did not supply here is
> that you are running 64-bit Windows 7.  That's the root of the problem.
>
> SoundRecorder.exe is a 64-bit executable, and lives in
> \Windows\System32.  When you are a 32-bit process on 64-bit Windows, and
> you try to refer to files in \Windows\System32, the operating system
> "helpfully" rewrites the path so you actually refer to
> \Windows\SysWOW64, which is where the 32-bit executables and DLLs live.
>
> Unlike almost every other utility, there is no 32-bit version of
> SoundRecorder.exe, so subprocess fails to find the executable and dies.
> Cmd.exe is a 64-bit process, so it looks in the real System32 and finds it.
>
> So, what are your options?  One answer is to install a 64-bit build of
> Python.  Another answer is to turn off the file system redirection using
> ctypes.windll.kernel32.Wow64DisableWow64FsRedirection (I just tried it
> -- it works).
>
> By the way, there is no point in using Popen with SoundRecorder.  It's a
> GUI application.  It doesn't use stdin and stdout.
In the command line using switches it does. I just need it to record a
.wav file for a specific duration like below:

subprocess.Popen(['SoundRecorder','/FILE',r'c:\Users\david\test01.wav','/DURATION','0000:00:02'],shell
= True)

The first suggestion, to disable using the 32 bit version, still left
me with a 'SoundRecorder not found pop-up window'. I tried the 2.7 64
bit and it works wonderfully now.

Thanks for your help,
David

> --
> Tim Roberts, [hidden email]
> Providenza & Boekelheide, Inc.
>
> _______________________________________________
> python-win32 mailing list
> [hidden email]
> http://mail.python.org/mailman/listinfo/python-win32
_______________________________________________
python-win32 mailing list
[hidden email]
http://mail.python.org/mailman/listinfo/python-win32
Reply | Threaded
Open this post in threaded view
|

Re: Issuing a command via subprocess, other methods in Windows 7

David Hutto-2
In reply to this post by Tim Roberts
On Wed, Feb 22, 2012 at 12:59 PM, Tim Roberts <[hidden email]> wrote:

> David Hutto wrote:
>> initiates the START command, which means it works, but not on command
>> line when using SoundRecorder which is in the system32 dir. I thought
>> it might be a directory placement problem, but don't know if that
>> would be the correct way to fix it, or if that's even the problem.
>>
>> Any ideas why the above works for the START, and not the
>> SoundRecorder, when both work on the windows command prompt when typed
>> directly in?
>
> Yes.  The one critical piece of information you did not supply here is
> that you are running 64-bit Windows 7.  That's the root of the problem.

Quick question, How did you know this?


>
> SoundRecorder.exe is a 64-bit executable, and lives in
> \Windows\System32.  When you are a 32-bit process on 64-bit Windows, and
> you try to refer to files in \Windows\System32, the operating system
> "helpfully" rewrites the path so you actually refer to
> \Windows\SysWOW64, which is where the 32-bit executables and DLLs live.
>
> Unlike almost every other utility, there is no 32-bit version of
> SoundRecorder.exe, so subprocess fails to find the executable and dies.
> Cmd.exe is a 64-bit process, so it looks in the real System32 and finds it.
>
> So, what are your options?  One answer is to install a 64-bit build of
> Python.  Another answer is to turn off the file system redirection using
> ctypes.windll.kernel32.Wow64DisableWow64FsRedirection (I just tried it
> -- it works).
>
> By the way, there is no point in using Popen with SoundRecorder.  It's a
> GUI application.  It doesn't use stdin and stdout.
>
> --
> Tim Roberts, [hidden email]
> Providenza & Boekelheide, Inc.
>
> _______________________________________________
> python-win32 mailing list
> [hidden email]
> http://mail.python.org/mailman/listinfo/python-win32
_______________________________________________
python-win32 mailing list
[hidden email]
http://mail.python.org/mailman/listinfo/python-win32
Reply | Threaded
Open this post in threaded view
|

Re: Issuing a command via subprocess, other methods in Windows 7

Tim Roberts
David Hutto wrote:
> On Wed, Feb 22, 2012 at 12:59 PM, Tim Roberts <[hidden email]> wrote:
>>
>> Yes.  The one critical piece of information you did not supply here is
>> that you are running 64-bit Windows 7.  That's the root of the problem.
> Quick question, How did you know this?

It was the only explanation that fit your symptoms.  When files in
System32 magically disappear when you run a 32-bit Python, the only
reasonable explanation is that you are seeing file system redirection on
a 64-bit system.  It was actually just an educated guess, but I made it
sound like an established fact in order to enhance my reputation as a
miracle worker.  ;)

--
Tim Roberts, [hidden email]
Providenza & Boekelheide, Inc.

_______________________________________________
python-win32 mailing list
[hidden email]
http://mail.python.org/mailman/listinfo/python-win32