Solved first bat file give second bat file orders


stier

New member
Local time
2:43 AM
Posts
18
OS
win 11
dear helpers,

I'm looking for a bat script that can open another bat file and issue commands. In the 2nd bat file there is a selection menu that contains some options that I want to be automatically disabled when I open the first bat file. As examples we take options 3,4,5,6

And when I see that everything has gone well, z is the start command to execute everything from the option that is still enabled.

thank you very much and i hope somebody can help me.
 

My Computer

System One

  • OS
    win 11

My Computer

System One

  • OS
    Windows 11
    Computer type
    PC/Desktop
    Manufacturer/Model
    HP Pavilion
    CPU
    AMD Ryzen 7 5700G
    Motherboard
    Erica6
    Memory
    Micron Technology DDR4-3200 16GB
    Graphics Card(s)
    NVIDIA GeForce RTX 3060
    Sound Card
    Realtek ALC671
    Monitor(s) Displays
    Samsung SyncMaster U28E590
    Screen Resolution
    3840 x 2160
    Hard Drives
    SAMSUNG MZVLQ1T0HALB-000H1
CALL the second batch file from the first.

or you could use start

batchfile1.cmd

Code:
@echo off
echo.
echo.
echo this is batchfile1
echo.
echo press enter to run  %~dp0batchfile2.cmd in this same window
echo.
pause

start "" /b /w cmd /c %~dp0batchfile2.cmd
echo.
echo.
echo we are now back to batchfile1
echo.
pause


batchfile2.cmd

Code:
@echo off
:start
cls
echo.
echo this is batchfile2
echo _____________
echo.
echo.
echo [1] Winget Upgrade
echo.
echo [2] Winget ALL
echo.
echo [0] Exit this batch file
echo.
echo.
SET /P M= Type 1 or 2 or 0 to select from the above  then press Enter:
if not defined M goto :start
for /l %%a in (0,1,2) do if "%M%"=="%%a" GOTO :CHOSENOK
GOTO :start
:chosenok
IF %M%==1 GOTO upgrade
IF %M%==2 GOTO all
IF %M%==0 GOTO :endthis

:upgrade
echo.
echo.
echo you selected option1 winget upgrade
echo.
pause
goto start

:all
echo.
echo.
echo you selected option2 WINGET UPGRADE --ALL
echo.
echo.
pause
goto start

:endthis
echo.
echo.
echo you selected option 0 exit this batch
echo.
pause
 
Last edited:

My Computers

System One System Two

  • OS
    Win7,Win11
    Computer type
    PC/Desktop
    CPU
    i5-8400
    Motherboard
    gigabyte b365m ds3h
    Memory
    2x8gb 3200mhz
    Monitor(s) Displays
    benq gw2480
    PSU
    bequiet pure power 11 400CM
    Cooling
    cryorig m9i
  • Operating System
    win7,win11
    Computer type
    PC/Desktop
    CPU
    pentium g5400
    Motherboard
    gigabyte b365m ds3h
    Memory
    1x8gb 2400
    PSU
    xfx pro 450
read my last post
 

My Computers

System One System Two

  • OS
    Win7,Win11
    Computer type
    PC/Desktop
    CPU
    i5-8400
    Motherboard
    gigabyte b365m ds3h
    Memory
    2x8gb 3200mhz
    Monitor(s) Displays
    benq gw2480
    PSU
    bequiet pure power 11 400CM
    Cooling
    cryorig m9i
  • Operating System
    win7,win11
    Computer type
    PC/Desktop
    CPU
    pentium g5400
    Motherboard
    gigabyte b365m ds3h
    Memory
    1x8gb 2400
    PSU
    xfx pro 450
thx you. i will look ad it tomorrow. I have already a second bat file. The first bat file must give orders to the second and i don't wanna change the second file, i mean the script.
 
Last edited:

My Computer

System One

  • OS
    win 11
thx you. i will look ad it tomorrow. I have already a second bat file. The first bat file must give orders to the second and i don't wanna change the second file, i mean the script.

Post both bat files, wrap them in code tags

Paste the code for the first bat file, select all the text and click on the following toolbar icon:

IMG_4775.jpeg

Paste the content of the second bat file and do the same then press “post reply” so these guys can help you further.
 

My Computers

System One System Two

  • OS
    Windows 11 Pro 23H2 Build 22631.4249
    Computer type
    PC/Desktop
    Manufacturer/Model
    Sin-built
    CPU
    Intel(R) Core(TM) i7-4770K CPU @ 3.50GHz (4th Gen?)
    Motherboard
    ASUS ROG Maximus VI Formula
    Memory
    32.0 GB of I forget and the box is in storage.
    Graphics Card(s)
    Gigabyte nVidia GeForce GTX 1660 Super OC 6GB
    Sound Card
    Onboard
    Monitor(s) Displays
    4 x LG 23MP75 - 2 x 24MK430H-B - 1 x Wacom Pro 22" Tablet
    Screen Resolution
    All over the place
    Hard Drives
    Too many to list.
    OS on Samsung 1TB 870 QVO SATA
    PSU
    Silverstone 1500
    Case
    NZXT Phantom 820 Full-Tower Case
    Cooling
    Noctua NH-D15 Elite Class Dual Tower CPU Cooler / 6 x EziDIY 120mm / 2 x Corsair 140mm somethings / 1 x 140mm Thermaltake something / 2 x 200mm Corsair.
    Keyboard
    Corsair K95 / Logitech diNovo Edge Wireless
    Mouse
    Logitech G402 / G502 / Mx Masters / MX Air Cordless
    Internet Speed
    100/40Mbps
    Browser
    All sorts
    Antivirus
    Kaspersky Premium
    Other Info
    I’m on a horse.
  • Operating System
    Windows 11 Pro 23H2 Build: 22631.4249
    Computer type
    Laptop
    Manufacturer/Model
    LENOVO Yoga 7i EVO OLED 14" Touchscreen i5 12 Core 16GB/512GB
    CPU
    Intel Core 12th Gen i5-1240P Processor (1.7 - 4.4GHz)
    Memory
    16GB LPDDR5 RAM
    Graphics card(s)
    Intel Iris Xe Graphics Processor
    Sound Card
    Optimized with Dolby Atmos®
    Screen Resolution
    QHD 2880 x 1800 OLED
    Hard Drives
    M.2 512GB
    Other Info
    …still on a horse.
Your problem description isn't entirely clear. Is your real intent is to enter specific "key input" into a running batch file?

For example, say this is your SECOND.BAT
Code:
@echo off
setlocal

:start
cls
echo.
echo [1] Pick Option A
echo [2] Pick Option B
echo [3] Pick Option C
echo [4] Pick Option D
echo.
echo [Z] Execute
echo.
echo.

SET /P M= Type 1,2,3 or 4 to select from the above then press Enter:
if not defined M goto :start

IF %M%==1 set list=%list%,1
IF %M%==2 set list=%list%,2
IF %M%==3 set list=%list%,3
IF %M%==4 set list=%list%,4
IF %M%==Z GOTO :endthis
goto :start

:endthis
echo.
if "%list:~0,1%" == "," (
   echo You selected options %list:~1%
) else (
   echo You selected options %list%
)

endlocal

To select the script's run-time options, you enter:
1
2
4
Z


Script now runs/exits with selections 1, 2 and 4.
Code:
[1] Pick Option A
[2] Pick Option B
[3] Pick Option C
[4] Pick Option D

[Z] Execute

Type 1,2,3 or 4 to select from the above then press Enter:
You selected options 1,2,4

If you know the exact typing, you can just copy that text into a file:
Code:
1
2
4
Z

Just use the redirect < symbol to send that file into the script.
Code:
SECOND.BAT < TEXT_FILE

[1] Pick Option A
[2] Pick Option B
[3] Pick Option C
[4] Pick Option D

[Z] Execute

Type 1,2,3 or 4 to select from the above then press Enter:
You selected options 1,2,4
 

My Computer

System One

  • OS
    Windows 7
In the existing second bat file there is a selection menu and if you click on 1 it turns on or off. and so on. Depends on where it is already saved, but now I want to create a new bat file and when I open it, it automatically opens the existing second one and automatically disables options 3,4,5,6. All options are always automatically enabled when starting the second file. And if I have approved it, start with z.

I cannot upload the 2nd file due to: private reasons.
 

My Computer

System One

  • OS
    win 11
i got a code and it works fine only it press automatic z. Have you a solution?

@echo off
echo Main batch file started

REM Run slave.cmd and feed commands interactively
(
echo 3
timeout /t 1 /nobreak >nul
echo 4
timeout /t 1 /nobreak >nul
echo 5
timeout /t 1 /nobreak >nul
echo 6
timeout /t 1 /nobreak >nul
) | cmd /c slave.cmd



echo Main batch file completed
pause
 

My Computer

System One

  • OS
    win 11
Why is a timeout required between each selection? If the second batch file is a normal script, it will wait for the buffered input no matter how long it takes before it's ready to read the next input line.
Your first script types "3", "4", "5", "6". Why doesn't it type a "Z"?

If you can't share the second script, then it's difficult to understand why this answer doesn't work.
 

My Computer

System One

  • OS
    Windows 7
that's what i get from ai machine and without the time out is also working. I have tried.
if everything done normal script close automatic and now not. See the key down what now is working for me. Can you tell me how i do that script automatic close?

Code:
@echo off
echo Main batch file started

REM Run slave.cmd and feed commands interactively
(
    echo 3
    echo 4
    echo 5
    echo 6
    timeout /t 60 >nul
) | cmd /c slave.cmd
 

My Computer

System One

  • OS
    win 11
If you're typing in CMD window, what keys are you typing? What comes after "6"?
 

My Computer

System One

  • OS
    Windows 7
This is the hole list. Why you ask?

Set "opt1=%on%"
Set "opt2=%on%"
Set "opt3=%on%"
Set "opt4=%on%"
Set "opt5=%on%"
Set "opt6=%on%"
Set "opt7=%on%"
Set "opt8=%on%"
Set "opt9=%on%"
Set "optP=%on%"
Set "optT=%on%"
Set "optD=%on%"
Set "optO=%off%"
Set "optS=%on%"


and type z is for start manual or waiting 60 sec because i use the code above to start the slave.cmd. Normal must type all numbers and than z
 

My Computer

System One

  • OS
    win 11
You're saying the script allows to enter "Z" to start now, or it will count and automatically start after 60 seconds? Then why not just send a "Z" instead of waiting?
3
4
5
6
Z (don't need a timeout now)
 

My Computer

System One

  • OS
    Windows 7
because if i don't use the timeout i can't check of everything is turn off. everything works fine for me. Only the automatic exit for the slave.cmd not.

==================================update==========================================

i run it again and now it is closed the slave.cmd. Everything works now. Thx for all.
 
Last edited:

My Computer

System One

  • OS
    win 11

Latest Support Threads

Back
Top Bottom