open and pass multiple commands to other shell

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
tobwz
Posts: 30
Joined: 25 Feb 2022 03:21

open and pass multiple commands to other shell

#1 Post by tobwz » 18 Apr 2022 00:40

Assume I want to setup several environment variables and start a program from a certain directory.

In a DOS batch file I can (simplyfied) code therefore:

Code: Select all

set path_to_java64=D:\java\bin
set path_to_settings=D:\db\tools\DBeaver\mysettingsfolder
set PATH=%path_to_java64%;%PATH%
dbeaver.exe -data "%path_to_settings%"
When I double click on such a batch script then the program is successfully started.
But unfortunately the command prompt remains open even after program start.

I want to avoid having an opened Command Prompt window.

Is there a smart way to close the current Command prompt window (not: process) without killing the started window?

I guess not. So i had to go the hard way:

Therefore I have to open a second shell and pass multiple programs. The following does NOT work:

Code: Select all

set path_to_java64=D:\java\bin
set currpath=cd
set path_to_settings=D:\db\tools\DBeaver\mysettingsfolder
start "DBeaver64.bat" /B (set PATH=%path_to_java64%;%PATH% & cd /d "%currpath%" & dbeaver.exe -data "%path_to_settings%")
Whats wrong?

OJBakker
Expert
Posts: 90
Joined: 12 Aug 2011 13:57

Re: open and pass multiple commands to other shell

#2 Post by OJBakker » 18 Apr 2022 07:40

Code: Select all

dbeaver.exe
is similar to

Code: Select all

start "" /wait dbeaver.exe
so the cmd will wait until dbeaver.exe is closed before continuing and ending the script.
So change the first script to explicit use the start.exe command but without the /wait option and then the cmd-window will close after starting 'dbeaver.exe'.

Puccilillo
Posts: 8
Joined: 11 Apr 2022 09:33
Location: Italy
Contact:

Re: open and pass multiple commands to other shell

#3 Post by Puccilillo » 18 Apr 2022 09:44

Code: Select all

set path_to_java64=D:\java\bin
set path_to_settings=D:\db\tools\DBeaver\mysettingsfolder
set PATH=%path_to_java64%;%PATH%
start dbeaver.exe -data "%path_to_settings%"
As OJBakker wrote, just use the start command above.
Using start without the /wait will continue the execution of the batch script after launching the .exe.

Bye

tobwz
Posts: 30
Joined: 25 Feb 2022 03:21

Re: open and pass multiple commands to other shell

#4 Post by tobwz » 18 Apr 2022 23:41

I already know that the "start " command should be used.

The question is how to pass multiple command to this new terminal process.

When I start an external program with start a NEW process is opened with NOT inherited but the default environment is used.
So I have to pass some environment variables which need multiple commands

So again:: How do I open a new terminal/Command prompt and pass a sequence of commands to execute over there?

AR Coding
Posts: 53
Joined: 02 May 2021 21:16

Re: open and pass multiple commands to other shell

#5 Post by AR Coding » 19 Apr 2022 09:02

Is this what you mean?

Code: Select all

cmd /c dbeaver.exe -data "%path_to_settings%"
use cmd /k to keep the window open after execution

Eureka!
Posts: 137
Joined: 25 Jul 2019 18:25

Re: open and pass multiple commands to other shell

#6 Post by Eureka! » 19 Apr 2022 16:29

First: In my experience, it helps if you stay friendly. People here are willing to help and to spend their free time on *your* issue. Getting irritated likely scares them away. They are too skilled to waste their time on that.

That out of the way: as I am not one of those skilled people, I will give it a go :)
tobwz wrote:
18 Apr 2022 23:41
When I start an external program with start a NEW process is opened with NOT inherited but the default environment is used.
That is *very* a-typical. Are you 100% sure about that?
The external program will be stared as a child process of the current CMD.exe and therefor will inherit it's environment settings.
Here is what happens if Notepad is started from CMD after setting some environment variables (shown in Process Explorer):
2022-04-20 00_05_20-notepad.exe_1328 Properties.png
2022-04-20 00_05_20-notepad.exe_1328 Properties.png (41.47 KiB) Viewed 7108 times

If your goal is to run the following
set path_to_java64=D:\java\bin
set path_to_settings=D:\db\tools\DBeaver\mysettingsfolder
set PATH=%path_to_java64%;%PATH%
dbeaver.exe -data "%path_to_settings%"
without a "leftover" open CMD window, this should work:

Code: Select all

set "path_to_java64=D:\java\bin"
set "path_to_settings=D:\db\tools\DBeaver\mysettingsfolder"
set "PATH=%path_to_java64%;%PATH%"

start "" /D "c:\the folder that you want as the\working directory"   "c:\path to\dbeaver.exe"   -data "%path_to_settings%"

The "" after start are important; read START /? for details.


There is another option, that relies on Windows mechanics, but that is a little less straightforward.
So I suggest to try this first (and reply in a non-irritated way ;)).

Post Reply