6

Currently, I click + 3x while holding Alt to create four divided terminals within the same tab:
Screenshot1

  • In each of these, I need to run a different Python commnd:
    1. cd "C:\Users\Computador\Desktop\Test One" && python one.py
      
    2. cd "C:\Users\Computador\Desktop\Test Two" && python two.py
      
    3. cd "C:\Users\Computador\Desktop\Test Three" && python three.py
      
    4. cd "C:\Users\Computador\Desktop\Test Four" && python four.py
      
  • Currently, I paste these paths manually, pressing Enter:
    Screenshot2

Is there any way to achieve this same result but in an automated way?

  • I'm not referring to mouse autoclick and things like that, I'm referring to commands in PowerShell itself, or something like that, to achieve this result
5
  • 3
    +1 on this question. I didn't know you could do that, and its actually really useful to hold alt while click on + to get it inline.
    – LPChip
    Apr 11 at 12:21
  • cd could be made more efficient with environment variables, e.g.: cd "${env:UserProfile}\Desktop\Test <#>". Does python not support environment variables, such as python "${env:UserProfile}\Desktop\Test One\one.py"?
    – JW0914
    Apr 11 at 12:44
  • @JW0914 they're using batch, in which case it is %USERPROFILE%\Desktop\Test
    – LPChip
    Apr 11 at 12:48
  • @LPChip PowerShell - please see title and screenshots. Double ampersands [&&] are processed in PowerShell, whereas singles [&] are replaced with ;
    – JW0914
    Apr 11 at 13:01
  • @JW0914 ah. I tried && in my powershell and that didn't work, but ; did. nevermind then. :)
    – LPChip
    Apr 11 at 13:33

1 Answer 1

6

You can call windows terminal [wt] with the split-pane [sp] function to create a new window in split pane, and you can specify /w 0 to do so in the current window; essentially you can run this myscript.cmd:

wt /w 0 sp
cd "C:\Users\Computador\Desktop\Test One" && python one.py

wt /w 0 sp
cd "C:\Users\Computador\Desktop\Test Two" && python two.py

wt /w 0 sp
cd "C:\Users\Computador\Desktop\Test Three" && python three.py

:: -- Switch back to the first pane, so we get a nice 4 squared window.
wt /w 0 fp /t 0

wt /w 0 sp
cd "C:\Users\Computador\Desktop\Test Four" && python four.py
  • For more info and to get a list of all options, including switching between panes and windows and stuff: wt /?

If it doesn't work correctly, you can put the command on one line too, e.g. creating a new tab to run ping within, returning focus back to the first tab while ping runs:

# cmd:
  wt /w 0 sp paping 8.8.8.8 -p 443 && wt /w 0 fp /t 0

# powershell:
  wt /w 0 sp paping 8.8.8.8 -p 443;wt /w 0 fp /t 0

EDIT: Based on this question, I've created the following function and stored it in my profile:

function RunSplit {
    param (
        [string]$program
    )
    $command = "wt /w 0 sp $program;wt /w 0 fp /t 0"
    Invoke-Expression $command
}

I can now type RunSplit "ping google.com" to ping google in a separate tab.

enter image description here

6
  • Hello @LPChip, thank you in advance for your time and attention, I put a check mark in the answer but I did some additional tests by putting a sleep(5) in the Python codes to look slowly at the execution, I noticed that all 4 files are being executed in the same split (first/main) instead of each code being executed in one of 4 different parts, could you help me solve this issue, please? Apr 11 at 19:16
  • I tried to adjust according to your additional instructions but I was unsuccessful. Apr 11 at 19:17
  • Remove the enters, and put each row on its own line, that should do it.
    – LPChip
    Apr 11 at 19:21
  • I tried to do this but it generating new tabs instead of splitting the actual tab. Apr 11 at 19:28
  • Try it like this: wt /w 0 sp cd "C:\Users\Computador\Desktop\Test One";python one.py;wt /w 0 fp /t 0
    – LPChip
    Apr 11 at 19:32

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .