run exe with parameters silently from batch file - windows

I want to execute an executable along with it's parameters from a Batch file silently without printing anything on the console from the executable and the executable shouldn't be executed from another console(it shouldn't open another command-prompt to execute). For that I tried with start command as following and couldn't execute it.
start "C:\myApp.exe -mode='a' -inputFilePath='%filePath%'" -i silent
Where %filePath% is a variable and -mode,-inputFilePath are the arguments to my executable.
Please correct me for anything wrong in above statement and help me out in this. Thanks!

From your batch file, just execute the following:
C:\myApp.exe -mode='a' -inputFilePath='%filePath%' >NUL
the >NUL redirects the output to nothing for that command.

Related

nircmd: I can't run another batch file with nircmd.exe?

I have wrote a batch file that i want to run another program with nircmd.exe. But the problem is i can't run it? The batch file(Matrix.bat) runs correctlyby double-click it. But when i trying to open it with nircmd.exe, it doesn't run? why?
i tried two method:
RunMethod1.bat (for runing another batch file)
SET INSTALLPATH=d:\atlantic
start %INSTALLPATH%\nircmd exec show %INSTALLPATH%\Matrix.bat
RunMethod1.bat (for runing another batch file)
SET INSTALLPATH=d:\atlantic
%INSTALLPATH%\nircmd exec show %INSTALLPATH%\Matrix.bat
The exec command in nircmd does not run batch files but executable files. Change your code to
start "" "%INSTALLPATH%\nircmd.exe" exec show "%comspec%" "%INSTALLPATH%\Matrix.bat"
Now, nircmd executes a cmd instance that will handle the batch file execution
The problem was in path of nircmd.exe. I set path of nircmd but i didn't know why it isn't work correctly? with "pushd" command i set the path of cmd into where nircmd.exe exist. and Bow!!! everything works cerrectly. Maybe a syntax problem. If everyone know that say it here.
SET INSTALLPATH=d:\atlantic
pushd %INSTALLPATH%
nircmd exec show Matrix.bat

Scheduling automated scripts suite run from schedular

So I tried and tried but couldn't figure out this one for some reason.
how can I run a task from a desired directory instead of System32 directory where cmd.exe is.
so, when I schedule a task and try to run it ..
command prompt suppose to go to "c:\users\aaa\bbb\ccc" and then pass the argument.
Instead, It's starts at c:\Windows\System32 and fails.
Could anybody help me with this please?
I really appreciate it.
Thank you.
EDIT --
so, now I have a run.bat file with following content in it ...
C:\Users\aaa\bbb\ccc\dd (location to my testrunner.bat file)
testrunner.bat Scripts/all.suite website-address ie (command for the task I wanna perform)
net stop schedule (since window is poping up and going away way to fast, I added this to stop it (not working))
type run.bat
#echo off
cd C:\Users\aaa\bbb\ccc\dd
rem this will show all files in dir
rem is the file you're expecting listed?
dir
rem notice how you can make comments with a leading rem(ark)
#echo starting scripts\all.suite
rem you have to change this to have the full path using Windows X:\dir\dir conventions
c:\home\Scripts\all.suite website-address
#echo done running scripts\all.suite website-address
#echo shutting down
net stop schedule
So its still not clear exactly to me your goal. The reason I added the cd c:\... command is that will **C**hange **D**irectory to the path specified.
This is what you need so you can "run a task from a desired directory instead of System32".
Copy everything from the first #echo off to the last net stop and using notepad, paste it into a file, fix command names and paths website-urls, etc, then save that file to c:\temp\testrunner.bat.
Open a cmd.exe window and test that the script works. Just paste c:\temp\testrunner.bat on to cmd-line and hit enter. If that works, then made an entry in the scheduler to run c:\temp\testrunner.bat . I don't know the specifics of running a script for scheduler, so look for clues on the input screen. Is the an option to run 'now'?
If the .bat file doesn't work from the command-line, then you have to fix the file before you try running it in the scheduler. As your command Scripts/all.suite website-address is a little vague, you'll do better to post a new question asking for help to fix the .bat file and use a sample command that people will be able to use on their PCs at home.
IHTH.

Disable force-close when batch file being called has an error

If the title seems vague, What I mean is that if you call a batch file through cmd or another batch file, how do you make it that the batch file being called, when it has an error, does not force-close the batch file that is calling it? My purpose is that if the batch file being called has an error, I won't redirect stderr to null, I'll just show it, and i'll make the launcher automatically (user choice) run debug mode or what most people call #echo on lol, and make the user reproduce the error.
HERE is the batch file (Launcher) that calls the program.
HERE is the program that is being called.
call will run the program in the current shell process. cmd /c (or perhaps %COMSPEC% /c) will run it in another process, thus allowing you to catch errors.
So, the calling batch file might be changed from
call easycommandline.bat
to
cmd /c easycommandline.bat
IF ERRORLEVEL 1 (
REM Do stuff when the script returns an error.
)

Background processes in batch with redirected output

I'm trying to run several background processes from a batch file and have the output directed to a file. Is it possible to do this in Windows? This is what I've tried but it end up directing the output of the start program rather then background process.
start myapp.exe > myapp.out 2>&1
Actually it is quite easy without using a helper batch file. You just need to run the application via cmd.exe instead, and make sure to escape the special characters so they pass through to cmd.exe.
You probably don't want to see an extra console window, so use the START /B option.
start /b "" cmd /c myapp.exe ^>myapp.out 2^>^&1
Each STARTed process must have its output directed to a unique file. Multiple processes cannot share the same output file.
I think the only chance you have is to create one batch file for each exe that you want to start. Inside the batch file you can redirect the output. The master batch file would then "start" the batch file, not the exe directly.
You just need to include an exit command at the end of each batch file:
start_myapp.cmd contains the following:
myapp.exe > myapp.out 2>&1
exit
then you can run
start start_myapp.cmd
and the output will be redirected

Windows .bat file doesn't execute its sequence

I created a simple install.bat file into my application folder, to execute its thing on windows.
But it only executes the first line of the .bat file.
Is there something that I need to add so it continues after the first one is done?
copy something somewhere
move something somewhereelse
gem install etc
Above are the type of commands that are in the .bat.
Do I need to anything something inbetween?
Is the first command in your batch file actually a copy command, or is it a command that's running another batch file?
Running a batch file from another by simply using the second batch file;s name will not return to the calling batch file.
If you want one batch file to invoke another and return you have to use the call command.
Are you overwriting a file? If so you'll need to add the /Y to the copy command to supress the prompt that asks if you want to overwrite the file.
Use the /h parameter to get help on the copy command. It will show this usage and some others.
As written above, all three lines will execute. I imagine that the second and third lines are failing. You should capture the output which will explain why those lines failed.

Resources