Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Python 2.7 and cmd on Windows 7 64 (files lost)

Reply
Thread Tools

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

 
 
Michel Claveau - MVP
Guest
Posts: n/a
 
      06-23-2011
Hi!

(sorry for my bad english...)

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

>>> import os
>>> os.system("dir C:\\Windows\\System32\\SoundRecorder.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?


@+
--
Michel Claveau


 
Reply With Quote
 
 
 
 
Thorsten Kampe
Guest
Posts: n/a
 
      06-23-2011
* 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
>
> >>> import os
> >>> os.system("dir C:\\Windows\\System32\\SoundRecorder.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
 
Reply With Quote
 
 
 
 
Tim Golden
Guest
Posts: n/a
 
      06-23-2011
On 23/06/2011 07:33, Michel Claveau - MVP wrote:
> Hi!
>
> (sorry for my bad english...)
>
> On Win 7 64 bits:
> Command-Line
> CD \Python27
> dir C:\Windows\System32\SoundRecorder.exe :==> OK
> Python.exe
>
>>>> import os
>>>> os.system("dir C:\\Windows\\System32\\SoundRecorder.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
 
Reply With Quote
 
Thorsten Kampe
Guest
Posts: n/a
 
      06-23-2011
* 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
 
Reply With Quote
 
Tim Golden
Guest
Posts: n/a
 
      06-23-2011
On 23/06/2011 09:08, Thorsten Kampe wrote:
> * 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.


Thanks: should have checked my sources before writing

TJG
 
Reply With Quote
 
Michel Claveau - MVP
Guest
Posts: n/a
 
      06-23-2011
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
--
Michel Claveau








 
Reply With Quote
 
Martin v. Loewis
Guest
Posts: n/a
 
      06-24-2011
> 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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: python cmd.Cmd auto complete feature Jean-Michel Pichavant Python 0 03-09-2011 10:17 AM
python cmd.Cmd auto complete feature Jean-Michel Pichavant Python 0 03-08-2011 05:28 PM
[exec cmd for cmd in cmds] =?ISO-8859-1?Q?Sch=FCle_Daniel?= Python 3 03-08-2006 03:21 PM
Interpreter-like help in cmd.Cmd Sarir Khamsi Python 4 06-26-2005 06:57 PM
read input for cmd.Cmd from file Achim Domma (Procoders) Python 2 06-03-2005 08:32 AM



Advertisments