Cannot execute Windows commands via Python in 64-bit

Discussion in 'Python' started by nsjmetzger@gmail.com, May 2, 2007.

  1. Guest

    I have a script that runs fine in Windows 2003 (32-bit). It basically
    calls the Windows defrag command. When I try the exact same code on
    Windows 2003 (64-bit) I get the following message:

    C:\Scripts>autodefrag.py
    Starting defragment: defrag -v C: >>c:/Scripts/DEFRAG20070502.log
    'defrag' is not recognized as an internal or external command,
    operable program or batch file.

    I have tried defrag.exe and even giving it the full path to
    defrag.exe. Always the same result. Here is the python code that is
    generating this error:

    cmd = "defrag -v C: >>c:/Scripts/DEFRAG20070502.log"
    print "Starting defragment: ", cmd
    errorlevel = os.system(cmd)


    Anyone know what the heck is going on and how to fix it? This code
    works fine on my 32-bit windows machines.
    Thanks.
     
    , May 2, 2007
    #1
    1. Advertising

  2. Larry Bates Guest

    wrote:
    > I have a script that runs fine in Windows 2003 (32-bit). It basically
    > calls the Windows defrag command. When I try the exact same code on
    > Windows 2003 (64-bit) I get the following message:
    >
    > C:\Scripts>autodefrag.py
    > Starting defragment: defrag -v C: >>c:/Scripts/DEFRAG20070502.log
    > 'defrag' is not recognized as an internal or external command,
    > operable program or batch file.
    >
    > I have tried defrag.exe and even giving it the full path to
    > defrag.exe. Always the same result. Here is the python code that is
    > generating this error:
    >
    > cmd = "defrag -v C: >>c:/Scripts/DEFRAG20070502.log"
    > print "Starting defragment: ", cmd
    > errorlevel = os.system(cmd)
    >
    >
    > Anyone know what the heck is going on and how to fix it? This code
    > works fine on my 32-bit windows machines.
    > Thanks.
    >

    Sounds like system can't find defrag. Usually this is because of a path
    issue. Are you running the script in the foreground or scheduled? Can
    you open a command prompt and enter the command and have it work? If
    you give full path, this shouldn't be the problem.

    -Larry
     
    Larry Bates, May 2, 2007
    #2
    1. Advertising

  3. minitotoro Guest

    On May 2, 3:07 pm, Larry Bates <> wrote:
    > wrote:
    > > I have a script that runs fine in Windows 2003 (32-bit). It basically
    > > calls the Windows defrag command. When I try the exact same code on
    > > Windows 2003 (64-bit) I get the following message:

    >
    > > C:\Scripts>autodefrag.py
    > > Starting defragment: defrag -v C: >>c:/Scripts/DEFRAG20070502.log
    > > 'defrag' is not recognized as an internal or external command,
    > > operable program or batch file.

    >
    > > I have tried defrag.exe and even giving it the full path to
    > > defrag.exe. Always the same result. Here is the python code that is
    > > generating this error:

    >
    > > cmd = "defrag -v C: >>c:/Scripts/DEFRAG20070502.log"
    > > print "Starting defragment: ", cmd
    > > errorlevel = os.system(cmd)

    >
    > > Anyone know what the heck is going on and how to fix it? This code
    > > works fine on my 32-bit windows machines.
    > > Thanks.

    >
    > Sounds like system can't find defrag. Usually this is because of a path
    > issue. Are you running the script in the foreground or scheduled? Can
    > you open a command prompt and enter the command and have it work? If
    > you give full path, this shouldn't be the problem.
    >
    > -Larry


    I have tried foreground and scheduled (neither works). I can run
    defrag from the command prompt with no problem. If I give it the full
    path in the script it still fails. I am completely befuddled. Help.
     
    minitotoro, May 2, 2007
    #3
  4. Larry Bates Guest

    minitotoro wrote:
    > On May 2, 3:07 pm, Larry Bates <> wrote:
    >> wrote:
    >>> I have a script that runs fine in Windows 2003 (32-bit). It basically
    >>> calls the Windows defrag command. When I try the exact same code on
    >>> Windows 2003 (64-bit) I get the following message:
    >>> C:\Scripts>autodefrag.py
    >>> Starting defragment: defrag -v C: >>c:/Scripts/DEFRAG20070502.log
    >>> 'defrag' is not recognized as an internal or external command,
    >>> operable program or batch file.
    >>> I have tried defrag.exe and even giving it the full path to
    >>> defrag.exe. Always the same result. Here is the python code that is
    >>> generating this error:
    >>> cmd = "defrag -v C: >>c:/Scripts/DEFRAG20070502.log"
    >>> print "Starting defragment: ", cmd
    >>> errorlevel = os.system(cmd)
    >>> Anyone know what the heck is going on and how to fix it? This code
    >>> works fine on my 32-bit windows machines.
    >>> Thanks.

    >> Sounds like system can't find defrag. Usually this is because of a path
    >> issue. Are you running the script in the foreground or scheduled? Can
    >> you open a command prompt and enter the command and have it work? If
    >> you give full path, this shouldn't be the problem.
    >>
    >> -Larry

    >
    > I have tried foreground and scheduled (neither works). I can run
    > defrag from the command prompt with no problem. If I give it the full
    > path in the script it still fails. I am completely befuddled. Help.
    >

    Copy and paste the traceback here for us.

    -Larry
     
    Larry Bates, May 2, 2007
    #4
  5. minitotoro Guest

    On May 2, 3:46 pm, Larry Bates <> wrote:
    > minitotoro wrote:
    > > On May 2, 3:07 pm, Larry Bates <> wrote:
    > >> wrote:
    > >>> I have a script that runs fine in Windows 2003 (32-bit). It basically
    > >>> calls the Windows defrag command. When I try the exact same code on
    > >>> Windows 2003 (64-bit) I get the following message:
    > >>> C:\Scripts>autodefrag.py
    > >>> Starting defragment: defrag -v C: >>c:/Scripts/DEFRAG20070502.log
    > >>> 'defrag' is not recognized as an internal or external command,
    > >>> operable program or batch file.
    > >>> I have tried defrag.exe and even giving it the full path to
    > >>> defrag.exe. Always the same result. Here is the python code that is
    > >>> generating this error:
    > >>> cmd = "defrag -v C: >>c:/Scripts/DEFRAG20070502.log"
    > >>> print "Starting defragment: ", cmd
    > >>> errorlevel = os.system(cmd)
    > >>> Anyone know what the heck is going on and how to fix it? This code
    > >>> works fine on my 32-bit windows machines.
    > >>> Thanks.
    > >> Sounds like system can't find defrag. Usually this is because of a path
    > >> issue. Are you running the script in the foreground or scheduled? Can
    > >> you open a command prompt and enter the command and have it work? If
    > >> you give full path, this shouldn't be the problem.

    >
    > >> -Larry

    >
    > > I have tried foreground and scheduled (neither works). I can run
    > > defrag from the command prompt with no problem. If I give it the full
    > > path in the script it still fails. I am completely befuddled. Help.

    >
    > Copy and paste the traceback here for us.
    >
    > -Larry


    I'm sorry, but I'm not familiar with traceback. How do I use it?
    Thanks.
     
    minitotoro, May 3, 2007
    #5
  6. minitotoro Guest

    On May 2, 4:15 pm, minitotoro <> wrote:
    > On May 2, 3:46 pm, Larry Bates <> wrote:
    >
    >
    >
    > > minitotoro wrote:
    > > > On May 2, 3:07 pm, Larry Bates <> wrote:
    > > >> wrote:
    > > >>> I have a script that runs fine in Windows 2003 (32-bit). It basically
    > > >>> calls the Windows defrag command. When I try the exact same code on
    > > >>> Windows 2003 (64-bit) I get the following message:
    > > >>> C:\Scripts>autodefrag.py
    > > >>> Starting defragment: defrag -v C: >>c:/Scripts/DEFRAG20070502.log
    > > >>> 'defrag' is not recognized as an internal or external command,
    > > >>> operable program or batch file.
    > > >>> I have tried defrag.exe and even giving it the full path to
    > > >>> defrag.exe. Always the same result. Here is the python code that is
    > > >>> generating this error:
    > > >>> cmd = "defrag -v C: >>c:/Scripts/DEFRAG20070502.log"
    > > >>> print "Starting defragment: ", cmd
    > > >>> errorlevel = os.system(cmd)
    > > >>> Anyone know what the heck is going on and how to fix it? This code
    > > >>> works fine on my 32-bit windows machines.
    > > >>> Thanks.
    > > >> Sounds like system can't find defrag. Usually this is because of a path
    > > >> issue. Are you running the script in the foreground or scheduled? Can
    > > >> you open a command prompt and enter the command and have it work? If
    > > >> you give full path, this shouldn't be the problem.

    >
    > > >> -Larry

    >
    > > > I have tried foreground and scheduled (neither works). I can run
    > > > defrag from the command prompt with no problem. If I give it the full
    > > > path in the script it still fails. I am completely befuddled. Help.

    >
    > > Copy and paste the traceback here for us.

    >
    > > -Larry

    >
    > I'm sorry, but I'm not familiar with traceback. How do I use it?
    > Thanks.


    Upon further investigation it turned out to be a windohs 64-bit issue
    (which is what I was afraid of). I did however find an asinine work
    around.

    Make a copy of defrag.exe from the system32 folder and paste it in the
    same directory as the python script. Voila! It now works. Piece of
    junk windohs... :-S
     
    minitotoro, May 4, 2007
    #6
  7. On 4 May 2007 12:24:38 -0700, minitotoro <>
    declaimed the following in comp.lang.python:


    >
    > Upon further investigation it turned out to be a windohs 64-bit issue
    > (which is what I was afraid of). I did however find an asinine work
    > around.
    >
    > Make a copy of defrag.exe from the system32 folder and paste it in the
    > same directory as the python script. Voila! It now works. Piece of
    > junk windohs... :-S


    Out of curiosity, what are the contents of PATH under the two OS
    variants?

    Maybe all you needed was to add the 32-bit defrag directory to the
    END (so stuff in it doesn't conflict with any 64-bit stuff of the same
    name) of the PATH environment variable.
    --
    Wulfraed Dennis Lee Bieber KD6MOG

    HTTP://wlfraed.home.netcom.com/
    (Bestiaria Support Staff: )
    HTTP://www.bestiaria.com/
     
    Dennis Lee Bieber, May 5, 2007
    #7
  8. Tim Roberts Guest

    minitotoro <> wrote:
    >
    >Upon further investigation it turned out to be a windohs 64-bit issue
    >(which is what I was afraid of). I did however find an asinine work
    >around.
    >
    >Make a copy of defrag.exe from the system32 folder and paste it in the
    >same directory as the python script. Voila! It now works. Piece of
    >junk windohs... :-S


    If you are using a 32-bit Python, then all references you make to
    \windows\system32 are automatically rewritten to \windows\syswow64. If
    defrag.exe is not present in \windows\syswow64, that could explain it.

    Unbelievable but true. Although we were all smart enough to handle the
    transition from \windows\system in Win16 to \windows\system32 in Win32,
    Microsoft apparently believes programmers have all grown too stupid to
    handle the transition to Win64 on our own.

    Some registry references are also silently rewritten.
    --
    Tim Roberts,
    Providenza & Boekelheide, Inc.
     
    Tim Roberts, May 5, 2007
    #8
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    3
    Views:
    1,864
    Timothy Bendfelt
    Jan 19, 2007
  2. Replies:
    9
    Views:
    1,062
    Juha Nieminen
    Aug 22, 2007
  3. Jeff.M
    Replies:
    6
    Views:
    207
    Lasse Reichstein Nielsen
    May 4, 2009
  4. Andrew Berg
    Replies:
    0
    Views:
    185
    Andrew Berg
    Oct 4, 2012
  5. Dennis Lee Bieber
    Replies:
    0
    Views:
    184
    Dennis Lee Bieber
    Oct 5, 2012
Loading...

Share This Page