Shutdown via batch file into infinite loop? - windows

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.

Related

How to use systemd timer to download and execute remote bash script?

I want to create a service called anything.service that downloads and executes a remote script ever 10 seconds I can create the timer but the service isn't executing the script.
Does anyone know how to achieve this?
I'm looking for it to contain something along the lines of:
ExecStart=/usr/bin/bash "wget -O- http://server.com/script.sh | sh"
I can run this script by calling it with
ExecStart=/usr/bin/bash /etc/systemd/system/.script
But I'm looking for a way to run the line within the anything.service file.

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"

I would like to create a batch script to run an already made bat script, delay for a few seconds and then type some commands

Need some help with this one (I'm new to batch scripting). So here's the problem:
I have a batch file called connection.bat:
- it connects to a network WiiU console, but it takes a few seconds to load the environment
- after it loads, it looks something like this:
#userid:
- that's when you can type some specific console commands (install and run mostly)
I want to make a batch file that does the following:
1. runs connection.bat
2. waits for it to finish loading the environment
3. and then type the install command
I tried doing it this way:
cd C:\test\connection.bat install -1 10.xx.xx.xx testupload.pkg
but it doesn't work, because it needs to connect first to the console
Is there a way to do this?
I always use ping to add a delay in batch files:
ping 0.0.0.0 > nul
adds a 3 second delay

Command failed when redirection failed

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?

Automatically connect to FTP server using batch commands, continue with batch script and then run FTP commands when necessary

Here's what I wish to do. Is it possible using a batch (Windows XP) file?
Prompt user to login to a FTP server.
Carry on with the rest of the batch commands, whilst keeping the FTP session/login alive.
Use the FTP PUT command when required with a batch command.
No, I cannot think of a way to keep the ftp process alive while continuing to run the batch file, and sending commands to the ftp process.
However, if this fits your needs, your batch file can collect all the data it needs first, generate a file containing all the ftp commands, then pass that file to ftp.exe as a last step.
For example:
SET /P ftpuser=Username:
SET /P ftppass=Password:
:: generate ftp script file
ECHO %ftpuser% > ftpcommands.txt
ECHO %ftppass% >> ftpcommands.txt
ECHO put file.txt >> ftpcommands.txt
ECHO quit >> ftpcommands.txt
:: now call ftp and have it process all the commands
ftp -s:ftpcommands.txt server.com
Windows ftp supports batch processing with its -s switch. However, there is no good way to keep an FTP session alive while waiting for more commands. The ftp command will process its -s script from start to finish and then exit.
Other than having the batch script generate the script used by ftp -s and running it as needed, the only solution I can think of would be to map the FTP server as a drive letter and copy as needed.

Resources