2

I want to concatenate several bash commands in a python file. Doing that for one command works:

import os
os.system('ls -l')

However if I dont know how to concatenate with another command like pwd

Kiko
  • 57
  • 6

2 Answers2

4

Use && and so:

import os
os.system('ls -l && pwd')

This will execute pwd on the successful execution of "ls -l"

Raman Sailopal
  • 12,320
  • 2
  • 11
  • 18
1

Use a semicolon if you want to always execute command 2, regardless of whether or not command 1 ran successfully:

import os
os.system('ls -l; pwd')
Timur Shtatland
  • 12,024
  • 2
  • 30
  • 47