Search code examples
pythonvisual-studio-codeterminal

How to put split terminal command ("ctrl+shift+5") in a python script in vs code in linux?


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?


Solution

  • 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