Solved first bat file give second bat file orders


stier

Member
Local time
9:12 PM
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 My Computer

At a glance

win 11
OS
win 11

My Computer My Computer

At a glance

Windows 11AMD Ryzen 7 5700GMicron Technology DDR4-3200 16GBNVIDIA GeForce RTX 3060
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
can you help me further because i don't understand it.
 

My Computer My Computer

At a glance

win 11
OS
win 11
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 My Computers

  • At a glance

    Win7,Win11i7-97002x16gb 3600mhz
    OS
    Win7,Win11
    Computer type
    PC/Desktop
    CPU
    i7-9700
    Motherboard
    gigabyte b365m ds3h
    Memory
    2x16gb 3600mhz
    Monitor(s) Displays
    benq gw2480
    PSU
    bequiet pure power 11 400CM
    Cooling
    cryorig m9i
  • At a glance

    win7,win11i5-84002x8gb 3200
    Operating System
    win7,win11
    Computer type
    PC/Desktop
    CPU
    i5-8400
    Motherboard
    gigabyte b365m ds3h
    Memory
    2x8gb 3200
    PSU
    xfx pro 450
can you make an example?
 

My Computer My Computer

At a glance

win 11
OS
win 11
read my last post
 

My Computers My Computers

  • At a glance

    Win7,Win11i7-97002x16gb 3600mhz
    OS
    Win7,Win11
    Computer type
    PC/Desktop
    CPU
    i7-9700
    Motherboard
    gigabyte b365m ds3h
    Memory
    2x16gb 3600mhz
    Monitor(s) Displays
    benq gw2480
    PSU
    bequiet pure power 11 400CM
    Cooling
    cryorig m9i
  • At a glance

    win7,win11i5-84002x8gb 3200
    Operating System
    win7,win11
    Computer type
    PC/Desktop
    CPU
    i5-8400
    Motherboard
    gigabyte b365m ds3h
    Memory
    2x8gb 3200
    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 My Computer

At a glance

win 11
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 My Computers

  • At a glance

    Windows 11 Pro 25H2 Build 26200.9168Intel(R) Core(TM) i7-4770K CPU @ 3.50GHz32.0 GB of I forget and the box is in storage.Gigabyte nVidia GeForce GTX 1660 Super OC 6GB
    OS
    Windows 11 Pro 25H2 Build 26200.9168
    Computer type
    PC/Desktop
    Manufacturer/Model
    Sin-built 2013
    CPU
    Intel(R) Core(TM) i7-4770K CPU @ 3.50GHz
    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
    ROG SupremeFX Formula 8-Channel High Definition Audio
    Monitor(s) Displays
    5 x LG 25MS500-B - 1 x 24MK430H-B - 1 x Wacom Pro 22" Touch Screen 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
    2000/500Mbps
    Browser
    All sorts
    Antivirus
    Kaspersky Premium
    Other Info
    ㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤ⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
    TP-Link BE9300 WiFi 7 Bluetooth 5.4 (Archer TBE550E)
    TP-Link TX201 V1 2.5GB Lan

    Grandstream HT812 - VoIP
    ASUS DSL-AX82U - Mesh
    ASUS RT-AC68U - Mesh
    ASUS RT-BE88U Router

    Brother MFC-L2880DW Printer

    I’m on a horse.
  • At a glance

    Windows 11 Pro 25H2 Build 26200.9168 (Wifes)13th Generation Intel® Core™ i5-1340P Process...16GB LPDDR5-52001x Intel® Iris® Xe Graphics
    Operating System
    Windows 11 Pro 25H2 Build 26200.9168 (Wifes)
    Computer type
    Laptop
    Manufacturer/Model
    LENOVO Yoga 7 14IRL8 - Type 82YL
    CPU
    13th Generation Intel® Core™ i5-1340P Processor(Core™ i5-1340P)
    Memory
    16GB LPDDR5-5200
    Graphics card(s)
    1x Intel® Iris® Xe Graphics
    Sound Card
    Optimized with Dolby Atmos®
    Screen Resolution
    QHD 2880 x 1800 OLED
    Hard Drives
    M.2 512 GB SSD PCIe
    Mouse
    Logiteck MX Master 3S
    Internet Speed
    2000/500
    Antivirus
    Defender / Malwarebytes
    Other Info
    …still on a horse.


    Wireless Network: Wi-Fi 6E 2x2 AX; Bluetooth® 5.1 or above
    Ports: 1x 1 Novo button; 2 in 1 Audio Combo jack; Micro SD Card Reader; HDMI 1.4b; 2 x USB Type-C (TBT4)
    USB 3.2 Gen 2 DP 1.4a
    PD 3.0); 1 x USB 3.2 Gen1 Type A
    Camera
    1x 1080P FHD IR/RGB Hybrid with Privacy Shutter and Dual Array Microphone
    Graphics
    1x Intel® Iris® Xe Graphics
    Monitor
    14" WUXGA
    Form Factor
    Convertible Notebook
  • Windows 11 Pro 25H2 Build 26200.9168 (Wifes)

    Yoga 7 2-in-1 14IML9 - Type 83DJ

    Processor: Intel® Core™ Ultra 7 155H Processor(Core™ Ultra 7 155H)

    Memory: 32GB LPD5X-7467

    Hard Drive: 1 TB SSD PCIe

    Wireless Network: 1x Wi-Fi 6E 2x2 AX; Bluetooth® 5.1 or above

    Ports: 1 x HDMI 2.1 TMDS; 1 x Novo Button; 1 x Combo Audio Jack
    2 x USB-C (USB 4.0)
    1 x USB-A 3.2 Gen 1

    Camera: 1080P FHD IR Hybrid with Dual Microphone

    Graphics: Intel® Arc™ Graphics

    Monitor: 14" 2.8K

    ...Where's my 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 My Computer

At a glance

Windows 7
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 My Computer

At a glance

win 11
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 My Computer

At a glance

win 11
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 My Computer

At a glance

Windows 7
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 My Computer

At a glance

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

My Computer My Computer

At a glance

Windows 7
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 My Computer

At a glance

win 11
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 My Computer

At a glance

Windows 7
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 My Computer

At a glance

win 11
OS
win 11
Back
Top Bottom