0

I want to run two commands in sequence:

  1. First go to /var/tmp/test folder
  2. Then svn checkout here

In order to do that I wrote this script:

open_folder = "cd /var/tmp/%s" % (folder_name)
cmd = "%s %s/%s/%s && %s %s/%s/%s" % (svn_co, svn_co_directory, fst_product_name, fst_firmware_name, svn_co, svn_co_directory, snd_product_name, snd_firmware_name) 
    os.system(open_folder)
    os.system(cmd)

It creates folder_name, but does not checkout into folder_name. It checked out to my current directory. Why?

Sameer Singh
  • 1,358
  • 1
  • 19
  • 47
caesar
  • 2,865
  • 11
  • 29
  • 36

1 Answers1

1

Try os.chdir(path) to change the directory. Or you could use the folder as a prefix in your second command. This explains, why cd won't work.

I would prefer to use subprocess.Popen(..) instead of os.system. It allows to specify a current working directory for the command you execute.

Community
  • 1
  • 1
LostAvatar
  • 795
  • 7
  • 20
  • thanks for comment. I looked at the explanation you sent. I want to ask one more question. Do you know what is the process and subprocess ? I mean what do they differ ? – caesar Aug 21 '13 at 09:58
  • 1
    I'm not sure if I get your question right. If you start your python program, it's execution is a process in the OS. By executing commands like `cd`, you invoke another executable. This executable runs in an own process, which is a subprocess of your python program, because you invoked it therein. I hope that answers your question. If somebody knows it better, please correct me. – LostAvatar Aug 21 '13 at 10:29