How to Open a Command Terminal in Linux

How to write a shell script to open four terminals and execute a command in each?

You could use a "for" loop, and a "&" to run xterm in background:


#!/bin/bash

# some older test, doesn't work and complains and I get this message on command line: "QApplication::qAppName: Please instantiate the QApplication object first"
# I also can't enter text after command executes
#echo "Hello World!"
#exec konsole --noclose -e cat ~/.aliases

for i in 1 2 3 4
do
# opens terminal but then I can't control terminal afterwards
xterm -hold -e "echo Hello My World" &
done

# didn't do anything
#exit 0

# didn't do anything except make me type exit an extra time where I executed my shell script
#$SHELL

Is there a way to launch a terminal window (or cmd on Windows) and pass/run a command?

Here is a working example showing how to open a Terminal window at a specific path (~/Desktop for instance) on macOS, from a renderer script:

const { app } = require ('electron').remote;
const atPath = app.getPath ('desktop');
const { spawn } = require ('child_process');
let openTerminalAtPath = spawn ('open', [ '-a', 'Terminal', atPath ]);
openTerminalAtPath.on ('error', (err) => { console.log (err); });

It should be easy to adapt it to any selected atPath...
As for running other commands, I haven't found a way yet...

And here is the equivalent working code for Linux Mint Cinnamon or Ubuntu:

const { app } = require ('electron').remote;
const terminal = 'gnome-terminal';
const atPath = app.getPath ('desktop');
const { spawn } = require ('child_process');
let openTerminalAtPath = spawn (terminal, { cwd: atPath });
openTerminalAtPath.on ('error', (err) => { console.log (err); });

Please note that the name of the terminal application may be different, depending on the Linux flavor (for instance 'mate-terminal' on Linux Mint MATE), and also that the full path to the application can be explicitly defined, to be on the safe side:

const terminal = '/usr/bin/gnome-terminal';

HTH...

How to kill all open terminals using command lines in CentOs

If you want to kill all open terminals except for the current one, you can use

kill $(pgrep bash)

pgrep bash lists the pids of all the active terminals

if the terminals refuse to die, you can use

kill -9 $(pgrep bash)

the "-9" is used to send the SIGKILL Signal to the process

How can I open the terminal in Visual Studio?


Visual Studio 2022/2019

Now Visual Studio has a built-in terminal:

Terminal SS

Menu ViewTerminal (Ctrl + ")

To change the default terminal

Menu ToolsOptionsTerminalSet As Default

Sample Image


Before Visual Studio 2019

From comments, the best answer is from Hans Passant.

  1. Add an external tool.

    Menu ToolsExternal ToolsAdd

    Title: Terminal (or name it yourself)

    Command = cmd.exe or Command = powershell.exe

    Arguments = /k

    Initial Directory = $(ProjectDir)

  2. Menu ToolsTerminal (or whatever you put in title)

  3. Enjoy!



Related Topics



Leave a reply



Submit