How to run .bat file in silent mode with parameters - windows

Hello i would like run in silent mode .bat file but I have two parameters that I will enter one after the other.
It is possible to run the .bat from the command line with the parameters ?
Thanks for helping
I tried #echo off launcher.bat but i don't now how can i set parameters

You can try sending the output to the NUL device.
launcher.bat param1 "param 2" > NUL

Related

Running a batch file which requires inputs directly from folder

I have a batch file which requires 4 command line inputs. When I execute the batch file on the command prompt, it displays help message asking to input 4 values.
When I run this file directly from the folder, it opens cmd and closes immediately.
Is it possible to modify the batch file, so that when I run from folder it will open the cmd and then display the help message.?
Following is a mini version of my problem with 1 command input. The script is for a License file generation
#ECHO OFF
GOTO :continue
:continue
SETLOCAL
IF "%1" == "" GOTO :Help
::Set the Command Line Options
SET ARVERSION=%1
::Create Directory
SET OUT_PATH=%cd%
ECHO Initiating Generation...
if not exist %OUT_PATH% mkdir %OUT_PATH%
::Create License File - Calling 'Subs' will create the output with actual Version
Subs ARVERSION %ARVERSION% Input.txt 1>%OUT_PATH%\License.txt
ECHO Scripts are created # %OUT_PATH%
ECHO Generation Completed...
GOTO :End
:Help
ECHO Starting License File Generation...
ECHO Usage:
ECHO InstallerScriptGen.bat AR_VERSION
ECHO AR_VERSION - Version (3.2 or 4.0 or 4.2)
ECHO Example : InstallerScriptGen.bat 3.2.2
ECHO Please Note that input of incorrect values will result in wrong generation.
:End
ENDLOCAL
"Running directly from the folder" (by which I assume you mean "clicking on the icon from within Windows Explorer") causes Windows Explorer to execute the equivalent of CMD /C <<batchfilename>>. When invoked with /C, CMD exits (and the CMD window closes) as soon as the batch file ends. You can force the window to stay open long enough to read the output by ending the script with either the PAUSE command (which will cause it to wait for the user to press any key), or the TIMEOUT command (which will wait the indicated number of seconds before continuing, without a keypress). See SS64's help for the PAUSE and TIMEOUT commands for more information.

Handle Windows command prompt input from keyboard and display output and also redirecting it to a file?

Though I can find few relevant questions such as Displaying Windows command prompt output and redirecting it to a file and How do I echo and send console output to a file in a bat script?, I could not fix my problem. I am working on Windows XP and running a few scripts using a batch file which uses STDIN and STDOUT handles.
Basically, I want to save the log file of command prompt. This is possible with "echo >> log.txt" in a batch file. However, this is not saving the outputs generated as a result of the script file. So I tried at the cmd prompt itself as D:>file.bat >"dir_path/log.txt". Again, this command saves the STDOUT to log.txt at the specified location. Since I need to get a few user inputs i.e. to use the STDIN handle, how do I achieve this in addition to saving the outputs of command prompts in separate file too?
The answer is simple:
#echo off
set /p answ1=Get user input1
set /p answ2=Get User input2
echo %answ1% and %answ2%>>log.txt
notepad log.txt
set /p "var=<log.txt"
type log.txt
Even if you redirect your .bat file to a file, you can output to the screen with >con.
Execute the following script with test.bat >test.out. It will prompt you for an input on the screen.
timeout -t 2
>con set /p "var1=Prompt1: "
ipconfig
>con set /p "var2=Prompt2: "
echo %var1% %var2%
>con echo %var1% %var2%
exit /b

A way to Pass a Variable to a Networked path Batch file and Execute

Going to lay this out the best I can and see if someone here can help me out a bit.
Here is my Code .bat on the Remote Server.
echo off
title SystemPlatzAll
set /p input=
findstr %input% SysPlatzAll.log >> Result.txt
%SystemRoot%\explorer.exe "Result.txt"
pause
What im trying to achieve is sending the %input% across the network to this batch file then excute and in return have the file save to the computer it is on. To which then the user will get the file opened from a shared folder i have on the drive.
can I use PsExec to send this over or is there another way?
I can get the .bat to execute with the following.
psexec \\HIFRP010.ad.foo.com -u hoem\hoemfooprod -p !foounit123 -e -h -accepteula -i 0 -d F:\Public\Logfiles\Systemplatz\foo\SystemPlatzBackup1.1\Final\NextTest.bat
pause
The above code will execute the Program.
But I want to know how or if it is possible to instead send %input% from one .bat to another.
Thank you in advance.
It is possible. I am not familiar with psexec, but you may be able to encapsulate the last parameter in doublequotes as is common on windows and pass input params directly on the command line. I do this using runas fairly often.
"F:\Public\Logfiles\Systemplatz\foo\SystemPlatzBackup1.1\Final\NextTest.bat paramFoo paramBar"

What is the correct batch file syntax?

What is the correct batch file syntax to run command-line application with arguments on windows 7?
C:\KindleGen\kindlegen.exe Htmlpage.html -c2
The bat file is in one folder with page that should be to processed.
Windows uses %1, %2, etc for the argument substitution.
Batch file test.bat contains:
c:\KindleGen\kindlegen.exe %1 -c2
Assuming the -c2 should always be applied
Call it with:
test somefile.html
If you need to run from the GUI, you can drag the .bat file to your desktop and double click it.
If the file to be processed is always the same, then you don't need the command line args, just put the complete command line in the bat file:
c:\KindleGen\kindlegen.exe Htmlpage.html -c2
If you need to get the user's input for a file name, you could have the .bat ask for it like this:
echo off
set /p fileName=Enter file name:
c:\KindleGen\kindlegen.exe fileName -c2
set /p done=Finished. Press enter...
When you click on that it will open a command window and wait for input, run the command, then wait for enter before closing the command window. Take that last line out if you want it to just close when done.
If you need a script that runs the command for all .html files in the current folder use:
echo off
for %%c in (*.html) do c:\KindleGen\kindlegen.exe %%c -c2
Try:
start "" "C:\KindleGen\kindlegen.exe" "Htmlpage.html" -c2

Batch file to determine if using Command Prompt

The last line in my batch file is pause. Is there any way to add a if condition to see if the script is run within command prompt or by double clicking to execute? I want to skip pause if it's running in command prompt.
...
...
if not RUN_IN_COMMAND_PROMPT (
pause
)
EDIT:
Hope to find a solution works in Windows Server 2003/2008, WinXP, Win7.
CALL :GETMYSWITCH %CMDCMDLINE%
IF /I "%MYSWITCH%" == "/C" ECHO I WAS STARTED IN THE EXPLORER & PAUSE
IF /I NOT "%MYSWITCH%" == "/C" ECHO I WAS STARTED IN A DOS SESSION
:GETMYSWITCH
SET MYSWITCH=%2
I know this is a year later but for future people searching you can use
If /I "%COMSPEC%" == %CMDCMDLINE% Goto SkipPause
pause
:SkipPause
It will skip the pause block if running from the command line and pause if running from batch file.
By definition, a shell script is always going to be run in a "command prompt". But try using the SESSIONNAME env var - it seems to NOT be present if the script was started by double-clicking instead of manually running it from a prompt.
Use the tty command.
Use the -s option and check the return value.

Resources