简体   繁体   中英

open new gnome terminal window from python in a specific directory or with “less” command

I have a GUI application from which I want to open new terminal windows:

  1. open new terminal in specific directory (' cd /home/abc/ ').
  2. open a text file with 'less' command (' less /home/abc/def.txt ').

tried 1 with:

subprocess.Popen(shlex.split('gnome-terminal -x tcsh -c "cd /home/abc/"'))

problem: it opens a new terminal window and closes it immediately

tried 2 with:

subprocess.Popen(shlex.split('gnome-terminal -x tcsh -c "less /abc/def.txt"'))

problem: opens the file with less command as wanted, but closes the terminal window when " q " is pressed to exit " less ".

Is there any way to make the new terminal windows stay alive?

I can give you a solution for your first problem. I tested it on Ubuntu 14.04.4 LTS:

import subprocess    
cmd = "gnome-terminal --working-directory=/home/begueradj/Desktop"
subprocess.Popen(cmd1, shell=True)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM