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
  • 2,054
  • 1
  • 7
  • 16
  • 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 from 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 sue 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")
Inder
  • 3,350
  • 8
  • 22
  • 35
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
  • 6