How to execute a comand in a specific directory to run in a WIndows Terminal window

1

I have been reading the docs https://docs.microsoft.com/en-us/windows/terminal/command-line-arguments and I just can't figure out how to open a program in a specific location to run using wt, I have tried:

wt -d d:\develop\config-server start gradlew bootrun
wt d:\develop\config-server\gradlew bootrun
wt d:\develop\config-server\gradlew.exe "bootrun" (with and without quotes)
wt -d d:\develop\config-server gradlew.exe bootrun
wt -d d:\develop\config-server gradlew bootrun

and many variants and I always get this kind of error

[error 0x80070002 when launching `gradlew bootrun']
windows
windows-10
windows-terminal
asked on Super User Feb 25, 2021 by Daniel Arechiga • edited Feb 25, 2021 by barlop

3 Answers

0

What are you trying to do? Are you trying to change where the program starts?

You need to use "startingDirectory" to specify it, use colon : to separate the value and the key, use double quotes to enclose the values and add commas to the end of each line except if it's the last line in a section and square brackets [].

And use either (forward) slashes / or double backslashes \\ to delimit the directories.

For example:

{
    "guid": "{574e775e-4f2a-5b96-ac1e-a2962a402336}",
    "colorScheme": "Campbell Powershell",
    "hidden": false,
    "name": "PowerShell",
    "source": "Windows.Terminal.PowershellCore",
    "startingDirectory" : "%Windir%/System32",
},

This makes PowerShell start in C:\Windows\System32

You need to edit the file located at path: %localappdata%\Packages\Microsoft.Windows.Terminal_*\LocalState\settings.json


I have pinned Windows Terminal to taskbar and run it by clicking its icon. I use it to run all the consoles (cmd, powershell, pwsh and python), I think this is the easiest way to use Windows Terminal.


Edit:

For your particular problem, use this:

{
    "guid": "{9224ff83-e8dc-451f-8d81-524594fa5b0d}",
    "closeOnExit" : false,
    "commandline: "d:\develop\config-server\gradlew.exe bootrun",
    "hidden": false,
    "name": "Gradle",
}

You still need to set the profile instance first.

Then, to do what you intended, the RIGHT syntax is:

wt -p Gradle -d "d:\develop\config-server"

To run in a different folder (I.E. %windir%\System32), use:

Universal:

wt -p Gradle -d C:\Windows\System32

Command Prompt:

wt -p Gradle -d %windir%\System32

PowerShell:

wt -p Gradle -d $Env:windir\System32

Now if you want to run this in another folder:

wt -p Gradle -d C:\Path\to\folder

-d switch is used to specify starting directory, -p switch specifies what you want to run, did you read the page you linked?

answered on Super User Feb 25, 2021 by Xeнεi Ξэnвϵς • edited Feb 25, 2021 by Xeнεi Ξэnвϵς
0

I found a solution but it requires WSL to be installed:

wt wsl --cd D:/develop/config-server ./gradlew bootrun
answered on Super User Feb 25, 2021 by Daniel Arechiga
0

Assuming I'm correctly understanding what you are attempting, try wt new-tab -d d:\develop\config-server d:\develop\config-server\gradlew bootrun. If that works, try shortening it to wt new-tab -d d:\develop\config-server gradlew bootrun, but I believe it's going to require the first version with fully-qualified path for the command as well.

Update -- Since neither of those worked for you, try:

wt new-tab -d d:\develop\config-server c:\Windows\System32\cmd.exe /c d:\develop\config-server\gradlew.exe bootrun.

I did a few tests with various proofs, such as wt new-tab -d c:\Windows\System32 c:\Windows\System32\cmd.exe /c dir /P.

Now if you have to throw any quotes or escaped characters in your commandline, it's a whole new story.

Also, I notice that the tab title is that of the defaultProfile in the Windows Terminal settings. However, the above command does not run in the Default Profile. To test this, I:

  • Changed my default profile to WSL Ubuntu
  • Did a wsl --terminate Ubuntu
  • Confirmed that it was stopped with wsl -l -v
  • Ran the above command
  • Checked wsl -l -v while the dir /P was still in progress - The Ubuntu WSL instance was not running.

You can set the title if desired with:

wt new-tab --title "Gradle" -d d:\develop\config-server d:\develop\config-server\gradlew bootrun

answered on Super User Feb 26, 2021 by NotTheDr01ds • edited Feb 27, 2021 by NotTheDr01ds

User contributions licensed under CC BY-SA 3.0