I'm trying to make my windows service run bat file with
psexec -accepteula -h -i 1 myapp.exe --p1 lala --p2 lalala
but closing the myapp cmd window results with "Terminate batch job y/n" question and service doesn't get the fact that it needs to restart itself.
In order to ignore this question, I googled and tried add
< nul
to the end of the command, but that didn't help. I assume that psexec doesn't get the fact, that "< nul" part is not for myapp but for psexec itself.
So how can I make my psexec finish without any questions about terminating batch job?
One way to do it is to create a SECOND batch file. The second file will call the first batch file and it will append "< nul".
For example, say you had a batch file which contained the following line:
python manage.py runserver
Name this file something like file1.bat
Then create a second batch file which contains the line:
file1.bat < nul
Name the second file something like file2.bat Then, execute the second file from that point on in order to call your program.
This worked for me in a Windows 10 environment. Good luck.
Related
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.
I am running multiple microservices locally for development purposes. Currently I am doing it by a .bat script, where I am calling other .bat files, which are starting my services. It starts multiple console windows, and this is not handy to navigate between outputs.
The script which is starting services now looks like this:
start cmd /k call api_one.bat
start cmd /k call api_two.bat
...
In api_xxx.bat I am starting iisexpress with my api.
I am looking for a way to make it more comfortable. For example by redirecting all of the outputs to a single one, with for example a prefix to identify from which script output lines are from.
I had a similar problem, where I was calling a batch file from a batch file which started another batch file.. to complicated to explain but let me get you some code that helped me:
content from test.bat:
set logname=.\log.log
if exist %logname% ( type nul > %logname%
)
echo Now starting example.bat>>%logname%
call C:\example.bat >>%logname%
echo finished example.bat>>%logname%
so now here is content of example.bat:
echo starting integrated commands
start /b cmd /k "C:\example2.bat"
[some code to check for a process that starts in example2.bat]
echo finished integrated commands
and the content of example2.bat can be whatever you want and is also displayed in the logfile.
Note that my example2.bat has an exit at the end, because example.bat checks if example2.bat is running. only when it finishes it goes on with the script. For myself it worked out I got everything from all 3 scripts into one logfile.
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
I have a batch file which at some point starts a ftp session. This ftp should create a log file.
When I run the batch file the command line, it works fine, but when it is started by the Windows task scheduler it does not. It does not create the ftp log file and even the ftp does not work.
This is a part of the batch file:
unzip -o %sourcedir%%FileName% -d %sourcedir%
rename "%sourcedir%OriginalFileName" newfilename.txt
move %sourcedir%%FileName% "%sourcedir%Archive\%FileName%"
ftp -s:ftpscript.scr >D:\TEMP\log\FTPgetLOG.txt
FC /a /w %sourcedir%t2dircompare.txt %sourcedir%target2dir.txt | FIND "FC: no dif" > nul
I start the batch file from the task scheduler with the argument: > D:\TEMP\log\DistributeFile.txt
When I look at the log file of the batch file, the ftp part looks like this:
C:\Windows\system32>ftp -s:PutT2DirToATBAS01.SCR 1>D:\TEMP\log\FTPgetLOG.txt
For some reason, it adds a space and a 1
Any ideas how to solve this?
Thanks!
1> means the same as >. It is always corrected in batch files as 1> is the correct format and > is compatability. 0 = stdinput, 1 = stdoutput, 2 = stderror. 3+ = a random file if one is open.
You need to check your environment and your TS account as a few don't have network access.
Thank you all for your input. It helped me a bit further, but the solution was to change the action in task scheduler like this:
Program/script: CMD
Add arguments: /c start "" "D:\temp\RunBatchFile.bat"
Start in: D:\temp**
So, DO NOT put the name of the batch file in the "Program/script" field.
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