1

Hi I would like to write a python script so that if i run that script it should open couple of applications and run some commands in console.Can any one guide me through it. Like example scripts and location to place it etc . P.S: I use Ubuntu as 17 as my OS.

Thankyou

Sumanth Madishetty
  • 3,425
  • 2
  • 12
  • 24
  • its different it isn't the same really he is calling for opening and running an application – Inder Jul 13 '18 at 17:18

2 Answers2

1

You can use os.open command to run any script within python script it will run as it would in a command line, for example:

import os


os.open("echo 7")

#this will print 7 on the terminal when you run the script

If in case you want to capture output of a script you run and use it in the script then I suggest you use os.popen, for example:

import os 

var=os.popen("cat /path/to/file")

print(var)

#this will print the file content

So in short anything that goes in os.open("here") will run as it would in a command line or terminal of your os.

If you want to run applications you will have to sub subprocess:

import subprocess

subprocess.call("spyder")

Alternatively you can use popen as well to open files:

import os

os.popen("spyder or subl")

os.open will not work. In regards to your specific request use the following code:

import os 
os.popen("cd /home/mypc/path ; subl")
Keivan
  • 1,300
  • 1
  • 16
  • 29
Inder
  • 3,711
  • 9
  • 27
  • 42
0

You can use the os library to execute system commands

import os
os.system("your command")

you can add your wanted application to the system path to be able to execute it using system commands

Sohaib
  • 13
  • 7