-1

i'm trying to write a python script which can execute two commands

sudo docker run --network=host --volume /home/villas/results:/villas/build/results --volume /home/villas/Docker-containers/webrtc-rtt.conf:/config.conf --privileged registry.git.rwth-aachen.de/acs/public/villas/node:master node /config.conf

and

sudo docker run --network=host --volume /home/villas/results:/villas/build/results --volume /home/villas/Docker-containers/webrtc-loopback.conf:/config.conf --privileged registry.git.rwth-aachen.de/acs/public/villas/node:master node /config.conf

in two different terminals at the same time. So what the script needs to do is, execute the first command in one terminal, and then create a new parallel terminal and the second command will be execute in second terminal.

To create a split terminal manually, I have to press ctrl+shift+5 But instead I want let my python script to do this job. Is there any way to code this into the python script?

4
  • I'm using VS code, "ctrl+shift+5" is split terminal in vs code Commented Jan 8 at 13:59
  • If you have a python script to create two separet terminals to run those two commands, can you include your python script in your post ? Commented Jan 8 at 14:58
  • @Philippe I didn't write the script so far, cause i don't know how to tell my script to execute 2 commands in 2 separet terminals. Does it matter? Commented Jan 8 at 19:37
  • Generally, you deliberately can't: Terminals read commands of this type from user input, not from program output. User input is trusted, program output is untrusted (even if the user ran a program deliberately, that program can be streaming content from the internet or another untrusted source), so there are sound security reasons to keep the two separate. Granted, there are tools that can be used to simulate input (xdotool &c), but using them is a smell Commented Jan 8 at 22:32

2 Answers 2

1

If you want to do this at the VS Code level, I'm pretty sure you can't (invoke general VS Code commands from terminal) right now. See Possible to invoke a VSCode extension command from command line?.

If you want to do this within a terminal in VS Code, look into terminal multiplexer software like tmux.

Alternatives:

  • Drive things from VS Code tasks. The simple thing to do would just be to create a task for each command and then a compound task that depends on them. You'd have to drag the terminal out to create the split view yourself though.
  • Drive things from a VS Code keyboard shortcut. runCommands and Shortcut for running terminal command in VS code would help with that, as well as the respective commands for creating and focusing terminals.
Sign up to request clarification or add additional context in comments.

Comments

0

Try this tasks.json:

{
    "version": "2.0.0",
    "tasks": [
        {
            "label": "Task One",
            "type": "shell",
            "command": "sudo docker run --network=host --volume /home/villas/results:/villas/build/results --volume /home/villas/Docker-containers/webrtc-rtt.conf:/config.conf --privileged registry.git.rwth-aachen.de/acs/public/villas/node:master node /config.conf",
            "presentation": {
                "group": "groupA"
            }
        },
        {
            "label": "Task Two",
            "type": "shell",
            "command": "sudo docker run --network=host --volume /home/villas/results:/villas/build/results --volume /home/villas/Docker-containers/webrtc-loopback.conf:/config.conf --privileged registry.git.rwth-aachen.de/acs/public/villas/node:master node /config.conf",
            "presentation": {
                "group": "groupA"
            }
        },
        {
            "label": "Run Both Tasks",
            "dependsOn": [
                "Task One",
                "Task Two"
            ]
        }
    ]
}

Steps to use :

  1. Create .vscode directory, and inside it create a new file tasks.json containing above content;
  2. On VSCode menu, Select Terminal->Run task->Run Both Tasks

2 Comments

Thank you Philippe for your answer, but i don't quite understand how this works, could you pls explain how it works or what i should do? Thanks a lot.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.