os.system('cd dir1 ... and executing next os.system command in that directory (dir1)

Discussion in 'Python' started by Irmen de Jong, Aug 12, 2003.

  1. Re: os.system('cd dir1 ... and executing next os.system command inthat directory (dir1)

    Sami Viitanen wrote:
    > I'm having problems with os.system.
    >
    > If I execute some 'cd directory' command with it, after that the script is
    > on the
    > same directory level as it was before the command.
    >
    > Any ideas ?


    os.system creates a new process that executes your command.
    Python's own process is not affected.

    You'll want to use os.chdir instead :)

    --Irmen
     
    Irmen de Jong, Aug 12, 2003
    #1
    1. Advertising

  2. Hello,

    I'm having problems with os.system.

    If I execute some 'cd directory' command with it, after that the script is
    on the
    same directory level as it was before the command.

    Any ideas ?

    Thanks in advance.
     
    Sami Viitanen, Aug 12, 2003
    #2
    1. Advertising

  3. Re: os.system('cd dir1 ... and executing next os.system command inthat directory (dir1)

    Sami Viitanen wrote:
    > Hello,
    >
    > I'm having problems with os.system.
    >
    > If I execute some 'cd directory' command with it, after that the script is
    > on the
    > same directory level as it was before the command.
    >
    > Any ideas ?


    If you use os.system, any environment or current directry changes there
    will only affect your shell and the child processes of it, but never the
    parent process (Python). This is true for at least Windows and *nix.

    By the way, why don't you just use os.chdir? :)

    -- Gerhard
     
    =?ISO-8859-1?Q?Gerhard_H=E4ring?=, Aug 12, 2003
    #3
    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. Deniz Bahar
    Replies:
    2
    Views:
    480
    Andrey Tarasevich
    Mar 9, 2005
  2. =?ISO-8859-2?Q?Miros=B3aw?= Makowiecki

    Reading of file by next of map file and by next of file descriptor.

    =?ISO-8859-2?Q?Miros=B3aw?= Makowiecki, Jul 10, 2007, in forum: C++
    Replies:
    1
    Views:
    795
    Alf P. Steinbach
    Jul 10, 2007
  3. Nathan Sokalski
    Replies:
    2
    Views:
    1,132
  4. Robert La Ferla
    Replies:
    8
    Views:
    139
  5. Tad McClellan
    Replies:
    3
    Views:
    152
    Edward Wijaya
    May 13, 2004
Loading...

Share This Page