How to disable input in batch script? - batch-file

I have a batch script (mine) that launches another batch script (theirs). Their batch script queries user input as part of the process, and I do not have access to modify it.
I need to suppress their batch script from querying input, meaning that when their batch script outputs: Press enter for step 2..., I want the user to be unable to interact with the script using their keyboard, hence the script should look like it's frozen.
How do I call their script from my script in such a way that the user is unable to interact with the input requests of their script?

Actually summing up the comments to make this not an unanswered question. You can try using the | (pipe) operator:
echo Haha! You will not be able to press any key!! | their.bat
Which will redirect STDOUT (Standard Out) of command echo Haha! You will not be able to press any key!! (Haha! You will not be able to press any key!!) to STDIN (Standard Input) of command theirs.bat.
Or, even read from nul:
their.bat < nul
I recommend reading https://ss64.com/nt/syntax-redirection.html and What does "&&" in this batch file? (second answer is better here.).

Related

Error while trying to write inputs to running console app with a batch

I have an exe file that I want to execute with a batch file.
Exe file is a third party console app that will prompt for input three times.
So I want to fill it in with an empty line, someText and someOtherText
(echo. echo someText echo someOtherText) | call config.exe remove
But I'm getting this error:
Cannot read keys when either application does not have a console or when console input has been redirected. Try Console.Read.
What could be the issue, please advise at least the direction to search?
I have the same error even if try to execute a simpler command like:
echo. | call config.exe remove
Your config.exe does not accept redirection at all. It requires real console buffers.
If you want to automate it, you could create another console application which will
start your config.exe using CreateProcessW
write your lines to STD_INPUT_HANDLE using WriteFile (ASCII, \n separated lines) or WriteConsoleInputW (if you need unicode characters)
after write is complete, just wait for config.exe termination and return exit code
Another simpler option is ConEmu terminal (I'm the author). There is GuiMacro scripting which could be easily used from console. So you could just run from your prompt or wrap in in batch file (run in ConEmu):
ConEmuC.exe -GuiMacro print "\nsomeText\nsome Other Text\n" & config.exe remove

How to automatically answer the user prompt from calling tsm command inside a .bat file

I am trying to write a set of tsm maintenance commands in .bat for performing some clean up on my Tableau Server.
The command tsm maintenance reset-searchserver, asks for a user prompt This operation will perform a server restart. Are you sure you wish to continue? (y/n): which I would like to answer automatically.
Stuff I have already tried:
I have already tried putting the command tsm maintenance reset-searchserver in a .bat file, say ABC.bat, and then typing echo y | ABC.bat on the command line. However, this did not work.
I also tried the method in which I saved the letter "y" in a text file, say Yes.txt, and then tying ABC.bat < Yes.txt on the command line. This did not work either.
Have also tried these two commands on the command line directly, they dont seem to work either:
echo y | tsm maintenance reset-searchserver and
tsm maintenance reset-searchserver<Yes.txt
you should use macro:
Edit macro file, put all your scripts and save as File.mac
Open administrative client and run:
C:\Program Files\Tivoli\TSM\baclient>dsmadmc -id=admin -pass=password macro c:\tmp\macro-file.mac

call enter in .bat file

I call .bat file from remote machine. In this .bat file I call .exe file, which want user to press Enter, after this .exe worked.
So, my question: is there any option to pass Enter in .bat file? Thanks for any help.
code of my .bat file
pushd \\server_name\\myfolder\\Reports\\
reportsupload.exe -e "http://mysite/ReportServer"
popd
If you are looking for a solution that does not rely on third-party programs, that will depend on how the program reportsupload.exe handles the request for pressing ENTER. If it reads the standard input stream, you might be able to manage it by changing the line to echo. | reportsupload.exe -e "http://mysite/ReportServer"; if it's handled by scanning the keyboard for the keypress, this will not work.
There may be third-party programs that can be configured to detect when the computer or a program is in a given state and trigger an action based on that state, but I'm not aware of any that don't require user intervention (e.g., pressing a key to execute a macro).

batch file start a program when closed

I need help writing a batch file that starts a program when I close the Command Prompt (batch file).
I know how to start a program when the batch file is running:
#echo off
Start [adress of application]
I believe it's not possible, because when you terminate the batch (by pressing the red 'X' on top), it will end imediately without doing anything.
But you can Read the user input, and if the user writes "Exit", it will run a program and close. I think you don't want that, but If you, then look at this: In Windows cmd, how do I prompt for user input and use the result in another command?

Is it possible to create a batch file that will call another batch file at some point and also supply it with a sequence of inputs

I have a batch file (lets say "test.bat"). Now when we run this test.bat it asks for user inputs during it's execution, For ex. user credentials and then shows a menu. The user can choose an option from the menu by entering a value after which the script will ask him for a lot more product specific details.
Question:
I need to call this test.bat inside another batch file and whenever test.bat requires user inputs my batch script should be able to provide a some inputs (a known sequence of menu options and inputs).
Is there anyway I can achieve this?
To call another batch file, I refer this link:
Several ways to call a windows batch file from another one or from prompt. Which one in which case?
To get user inputs:
Echo off
set /p x=path name:
echo path is %x%
pause

Resources