Python 2.7 and cmd on Windows 7 64 (files lost)

  • Thread starter Michel Claveau - MVP
  • Start date
M

Michel Claveau - MVP

Hi!

(sorry for my bad english...)

On Win 7 64 bits:
Command-Line
CD \Python27
dir C:\Windows\System32\SoundRecorder.exe :==> OK
Python.exe

==> Do not found the file !!!

and os.system("cmd /k") then "dir C:\Windows\System32\SoundRecorder.exe" do not found
anyway.

But:
{Ctrl-Z} in Python
then dir C:\Windows\System32\SoundRecorder.exe run OK

Therefore, is the problem only in Python?


@+
 
T

Thorsten Kampe

* Michel Claveau - MVP (Thu, 23 Jun 2011 08:33:20 +0200)
On Win 7 64 bits:
Command-Line
CD \Python27
dir C:\Windows\System32\SoundRecorder.exe :==> OK
Python.exe


==> Do not found the file !!!

and os.system("cmd /k") then "dir C:\Windows\System32\SoundRecorder.exe" do not found
anyway.

This is because 32-bit processes (Python, 32-bit cmd) cannot see the 64-
bit DLLs in System32.
But:
{Ctrl-Z} in Python
then dir C:\Windows\System32\SoundRecorder.exe run OK

Now you are running 64-bit Cmd.
Therefore, is the problem only in Python?

Of course not (see above).

Thorsten
 
T

Tim Golden

Hi!

(sorry for my bad english...)

On Win 7 64 bits:
Command-Line
CD \Python27
dir C:\Windows\System32\SoundRecorder.exe :==> OK
Python.exe


==> Do not found the file !!!

and os.system("cmd /k") then "dir C:\Windows\System32\SoundRecorder.exe" do not found
anyway.

But:
{Ctrl-Z} in Python
then dir C:\Windows\System32\SoundRecorder.exe run OK

Therefore, is the problem only in Python?

Certain commands, including "dir" and "copy" are not executables
in their own right, but merely subcommands of cmd.exe. You've
got two options in Python:

os.system (r"cmd /c dir c:\windows")

or:

subprocess.call (["dir", "c:\\windows"], shell=True)

which basically does it for you behind the scenes.

I hope that helps..

TJG
 
T

Thorsten Kampe

* Tim Golden (Thu, 23 Jun 2011 08:31:26 +0100)
Certain commands, including "dir" and "copy" are not executables
in their own right, but merely subcommands of cmd.exe.

Right, "internal commands".
You've got two options in Python:

os.system (r"cmd /c dir c:\windows")

os.system automatically runs a shell (cmd) - see the documentation.

Thorsten
 
T

Tim Golden

* Tim Golden (Thu, 23 Jun 2011 08:31:26 +0100)

Right, "internal commands".


os.system automatically runs a shell (cmd) - see the documentation.

Thanks: should have checked my sources before writing :(

TJG
 
M

Michel Claveau - MVP

Re !
This is because 32-bit processes (Python, 32-bit cmd) cannot see the
64-bit DLLs in System32.

Thanks.
You are right... but it is not enought.

This command: echo %PROCESSOR_ARCHITECTURE%
give the statut:
32: x86
64: AMD64

and DIR C:\Windows\System32\SoundRecorder.exe is OK in 64, not in 32.



But if, in 64 mode, I copy SoundRecorder.exe to sr.exe, then I rename
sr.exe to sr.txt, the file (which is not an executable) is not visible
in 32 mode.
And, if I move (or copy) sr.txt in an USB-drive, the file become visible
in 32 mode !!!???

Therefore, Windows has a "trick" for mark the file like visible, or not,
in 32 mode. What trick?


OK, it is not a Python problem.
Then... thanks again for your explanations.


@-salutations
 
M

Martin v. Loewis

Therefore, Windows has a "trick" for mark the file like visible, or not,
in 32 mode. What trick?

It's called file system redirection. When you access \windows\system32
in a 32-bit process, you *actually* access \windows\syswow64, which
has entirely different files.

The same also happens for parts of the registry.

Regards,
Martin
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,226
Members
46,815
Latest member
treekmostly22

Latest Threads

Top