[BangPypers] Execute Windows "shutdown" command through python !

Yuvi Panda yuvipanda at gmail.com
Tue Dec 29 19:15:36 CET 2009


os.system(r"shutdown.exe /s") works here, am on a Win7 machine.

sys.path doesn't have anything to do with os.system, it is used only when
searching for modules to load.

On Tue, Dec 29, 2009 at 11:37 PM, Pradeep Gowda <pradeep at btbytes.com> wrote:

> On Tue, Dec 29, 2009 at 12:58 PM, ™aßlเίlαslเ ► <abhilash.pin2 at gmail.com>
> wrote:
> > Hi,
> >     Yes 'shutdown' command is working absolutely fine from the command
> line
> > at Windows 64 bit,
> > but I have find something interesting is that :
> >
> >
> > import os
> > os.system("cmd")
> >
> > After running above code at python, then from that command window, I try
> to
> > run the 'shutdown ' command,
> > and its giving the error . I tried to search the "shutdown.exe" file at
> > C:\WINDOWS\system32 from the same
> > command window, and it can't locate it, where as I can find it by windows
> > command line.
> >
> >
> >
> >
> > On Tue, Dec 29, 2009 at 8:24 PM, Pradeep Gowda <pradeep at btbytes.com>
> wrote:
> >
> >> On Tue, Dec 29, 2009 at 9:22 AM, ™aßlเίlαslเ ► <abhilash.pin2 at gmail.com
> >
> >> wrote:
> >>
> >> > *import os
> >> > os.system("shutdown /?")*
> >> >
> >> > *its saying "shutdown is not an internal or external command or
> >> executable
> >> > batch file"*
> >>
> >> Is shutdown a valid command in the new OS?
> >> Atleast it looks like that from the error message.
> >>
> >> Try running `shutdown` from the command line and see whether you get
> >> the same error.
>
> try with the full path
> assuming shutdown.exe is in c:\windows\system32
>
> os.system("c:\\windows\\system32\\shutdown.exe")
>
> might work.
>
> Or is it c:\windows\system64 ??
> I do not have a windows PC to verify this.
>
> My hunch is that python's sys.path does not include the windows system
> directories.
>
> +PG
> _______________________________________________
> BangPypers mailing list
> BangPypers at python.org
> http://mail.python.org/mailman/listinfo/bangpypers
>



-- 
Yuvi Panda T
http://yuvi.in/blog


More information about the BangPypers mailing list