Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python & macOS: open new Terminal window from Python, passing command to be executed

I am using the following two lines of Python code to open a new Terminal window from a Python script, and this works fine:

import os
os.system('open -a Terminal .')

Now I would like to pass the new Terminal window a command to be executed, for example

ls

How can I do that?

like image 360
user3352382 Avatar asked Jan 23 '18 18:01

user3352382


People also ask

What is Python used for?

Python is a computer programming language often used to build websites and software, automate tasks, and conduct data analysis. Python is a general-purpose language, meaning it can be used to create a variety of different programs and isn't specialized for any specific problems.

What is A += in Python?

Dec 14, 2020. The Python += operator lets you add two values together and assign the resultant value to a variable. This operator is often referred to as the addition assignment operator.

Is Python hard to learn?

Python is widely considered among the easiest programming languages for beginners to learn. If you're interested in learning a programming language, Python is a good place to start. It's also one of the most widely used.

What is the basic language of Python?

Python has a simple syntax similar to the English language. Python has syntax that allows developers to write programs with fewer lines than some other programming languages. Python runs on an interpreter system, meaning that code can be executed as soon as it is written.


1 Answers

Try this

import appscript

appscript.app('Terminal').do_script('ls')  # or any other command you choose
like image 68
Ryan Loggerythm Avatar answered Sep 17 '22 13:09

Ryan Loggerythm