Command failed when redirection failed - windows

I'm running java program with bat script using command line:
start "AppName" /B %LOCAL_JAVA% -jar Starter.jar %* 1>out.txt 2>err.txt
I want to run bat script for a second time, java application will connect using TCP socket to first running and will pass script args. But instead of this I get error:
The process cannot access the file because it is being used by another process.
This is because files out.txt and err.txt are used by first running application.
How I can ignore failed stream redirection and run my command line?

start "AppName" /B %LOCAL_JAVA% -jar Starter.jar %* 1>%random%out.txt 2>%random%err.txt
like that? what do you mean it runs twice? does the command run twice or the program?

Related

running windows commands remotely

I'm trying to run a command remotely.
Here is what I've tried
wmic /node:"my_server" /user:my_username /password:my_pass process call create "cmd.exe \c dir C:>C:\temp\x.txt"
I can see the process id returned and I see a terminal running on the remote machine with that process id and that process is just stuck and the output x.txt is not generated.
Any idea how to make it work?
Any idea why the process is running but not doing anything?
My goal is to get the output back so it is not necessary to write to a file.

Command prompt started from batch file closes when operation is stopped

I am using a batch file to open a number of command prompts while I do some development work, however, I often need to restart 1 or more of the programs, while I'm debugging.
Is it possible to change the code to keep the window open to allow me to restart the application?
C:\
cd /d "C:\Users\me\mydir"
start redis-server
start celery worker -A celery_worker.celery --loglevel=info
start python manage.py runserver
I'd like to be able to kill and restart the celery worker / webserver whenever I make a change to the code.
START attempts to start the program directly; if the program uses stdin and stdout, this will invoke the console host to handle it. If you want a window that will remain open, instead of using START, try CMD /K - for the celery command line specifically, change start celery ... to CMD /K celery .... This starts a command prompt and runs the specified command; if the command terminates, the command prompt will remain, waiting for input (and will remain open until you exit it). Look at the output of CMD /?, or the page on cmd at SS64 for more information.

Shutdown via batch file into infinite loop?

Problem:
While running the batch file, it goes into infinite loop
Code:
shutdown -s -t 050
Output:
Ran the batch file
Output when i run in normal batch file:
Output when i run in admin batch file:
Question:
Now I wonder why this happens, and want to know how to run shutdown command normally from batch file, if not like this ?
You called the batch file shutdown
Use a name that is not a system command or internal command.

Task Sheduler: How to run batch file through cmd instead of taskeng.exe?

I wrote a simple script:
cd C:\TESTS\example
call git pull
cd C:\TESTS\example\AutoApp\bin\debug
start AutoApp.exe
I created daily task in sheduler and when task running it open taskeng.exe. That "command line" do not have any git/cmd command wich I use in script. And my application and git pull do not work.
If I open batch file by click on it, it works fine(git pull done and app run done) and run through cmd.
After firs option of anwser task is running all time.
After second option of anwser.
How to solve this problem?
Change the command line used in Task Scheduler to call cmd.exe to launch the batch file instead:
cmd /c "YourBatchFile.bat"
Or
%comspec% /c "YourBatchFile.bat"

What's the nohup on Windows?

I want to run a Java jar file like this:
java -jar spider.jar
How to run it on the background on Windows?
Like this on Linux:
nohup java -jar spider.jar > /var/tmp/spider.log 2>&1 &
You could use the Windows start command:
start /min java -jar spider.jar
This command is not really the same as nohup; but it might be suitable if you're happy with the Java process running in a separate minimised window. See http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/ntcmds.mspx
On Windows it's not normal that a process terminates once its parent was killed (like Unix-likes do it normally). Therefore there is no direct necessity for something like nohup. If you want to avoid the console window associated with it, you can use javaw but redirection won't work, then.
The only way to get the nohup behavior, where the process still runs after logging off (like for micro-services, analytic tools, server batch jobs etc.), is to run the .bat file with the start javaw -jar ... contents as either a service or a scheduled task.
save the following code to nohup.vbs, and add the directory to PATH.
Set args=Wscript.Arguments
Set ws=CreateObject("wscript.shell")
ws.Run args(0),0,true
then, run:
nohup "java -jar spider.jar > /var/tmp/spider.log"
Note that you should quote the full commands and the redirects.
For windows run following mentioned command in Command Prompt or in Terminal
nohup (file need to run) > (File you need to save the log) 2>&1
Ex:
nohup ./bin/windows/kafka-server-start.bat config/server.properties > ./MyKafka.log 2>&1

Resources