0

I want to run multiple commands in the same line after the previous is done.

I do the following bellow in a python script:

os.system("start_view myView && perl /home/user/Development/count_test.pl -rev 001 -project myproject && /usr/bin/python /home/user/Development/setDoneFlag_Count_Lines.py")

First I set a view in clearcase start_view myview, then I want to execute a perl program. Problem is it doesn't, it just sets the view (which I need in order for me to execute the perl program) but it never actually starts the perl program, so the question is am I doing anything wrong? It seems like start_view myView starts a new shell, so how do I execute a perl script in the newly created shell that the view starts?

Thanks in advance.

6
  • 2
    Maybe you show us start_view, since we can only guess… Commented May 22, 2015 at 13:35
  • 1
    Have you tried ; instead of && ? Perhaps the first command returns unsuccessfully. Commented May 22, 2015 at 13:45
  • If start_view is starting a new shell, it may simply not be returning. Perhaps start_view takes an option to allow it to start a process in the shell that it creates. Commented May 22, 2015 at 13:49
  • If this is like ClearCase, start_view will have an option (e.g. -c) where you can give it a command to run in the shell that has been launched in the view's context; if it exists, move the rest of your command into there. Additionally, && short-circuits upon failure (i.e. non-zero status), but ; does not (i.e. each command runs in succession). You can also do || for reverse short-circuit (i.e. execute only if there's a failure). For example try: /bin/true && echo TRUE || echo FALSE and /bin/false && echo TRUE || echo FALSE Commented May 22, 2015 at 14:12
  • Are you using Rational ClearCase's startview? Maybe you want setview -c your_commands_here? setview doc Commented May 22, 2015 at 14:13

1 Answer 1

1

In general multiple dependent commands should work when invoked from os.system():

>>> rv = os.system("ls /dev/null && grep mhawke /etc/passwd")
/dev/null
mhawke:x:1000:1000:mhawke:/home/mhawke:/bin/bash
>>> rv
0

But if one command fails (as determined by a non-zero exit status) the following commands are not executed:

>>> rv = os.system("ls /phantom && grep mhawke /etc/passwd")
ls: cannot access /phantom: No such file or directory
>>> rv
512

So, are you sure that start_view returns exit code 0? Are you sure that start_view returns at all? - could it be blocked waiting for input. Are you sure that the command isn't actually startview myView?

You could find out by executing this on the command line:

$ start_view myView
$ echo $?

If it displays 0, then try the next command in the chain until you find the culprit.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.