.bat file stuck at opening notepad document, not cancellable - batch-file

As I write bat file very infrequently, every time I write a new one gets me a new problem.
I have a bat file that is suppose to open a txt file and open an URL (which is a concatenated string, using current date), something like:
#echo off
notepad "C:\Users\username\somefile.txt"
start chrome "https://domain.com/%DATE%?some=parameters"
The text file opens fine and then nothing happens - console window gets stuck, not responding to ctrl-C. Apparently batch is suspended waiting for the notepad part to complete, because when I close the txt file window chrome opens the URL.
I tried < nul, > nul for the notepad part, but to no avail. What am I doing wrong?

If I see this correctly, you just need to use start with notepad also. It starts programs in another process so the script can continue.
#echo off
start notepad "C:\Users\username\somefile.txt"
start chrome "https://domain.com/%DATE%?some=parameters"

Related

Trying to start multiple .exe files in order with a bat file but first line fails and second line is successful

My code in the .bat looks like this.
"C:\users\reshade injector.exe"
C:\pathtogame\game.exe "added argument"
"c:\users\reshade injector.exe" <- if I open the actual file, it opens a command window and waits for my other application to launch. Is this a console app?
C:\pathtogame\game.exe "added argument" <- this works and launches my game
Another issue is that when launching the first .exe, a command window stays open. How do I make the command window not appear?
Can anyone help me with these two problems?
*edit for clarity
by opening the actual file, I mean double-clicking on the original reshade injector.exe.
When opening reshade injector.exe, two cmd windows open. They close as soon as I launch the game.exe.
I can't seem to get the reshade injector.exe to launch through the .bat file.
Batch will run any application it finds. If the application does not terminate (eg. it's waiting for user-input) then it will progress to the next instruction.
Some applications work by launching another (the user-interface) and then terminating, leaving the second application resident.
There's no way to tell without observing which approach any random application may take.
So - your batch should execute a file named c:\users\reshade injector.exe.
You say that "fails". Is there an error message generated? You would likely need to run the batch from the "command prompt" to see that message. Note that the Space between reshade and injector must be in the actual filename. If injector.exe is a file in a subdirectory called reshade, then you need a backslash between reshade and injector.
Having resolved the actual name of the first executable, try
#echo off
setlocal
start "" "firstexecutablename"
start "" "secondexecutablename" "arguments"
The first two lines prevent "command echoing" which is used for debugging and establish a "local environment" which ensures the "environment" for the batch file remains unchanged when the batch terminates. In the current case, these two lines are probably unnecessary, but it's SOP for batch files.
The batch should then close its session and window once it has attempted to launch the two applications.
The "" following start becomes the window-title. It can be any quoted string you like, but should not be omitted as start uses the first quoted string it finds as a window-title and may not recognise it as part of the executable/arguments.

Starting a program in batch file without stealing focus

I know how to do this in C++, C#, etc, but I've got a simple BAT file that does a couple operations on a file, opens it in Notepad++, and proceeds to the next file. Because I want to wait for it to finish running on 2 to 20 files, I want it to run in the background until it's finished.
Here's my line to open the file in Notepad++:
start "" /b "C:\Program Files (x86)\Notepad++\notepad++.exe" "%filepath%"
Is it possible to START a program so that it runs without stealing focus?
This is not a general solution, but for your specific requirement (notepad++) you could try command line option of notepad++.exe -systemtray
from notepad cmd line spec:
-systemtray
Start Notepad++ minimised in the system tray, aka notification area
(There is an option to start program minified start /min, but n++ does not honor it... it works with regular notepad, though)

Batch Files - Closing Opened Text Files

I currently have a Windows batch file that runs an .exe file that uses a text file. I am trying to have the Windows batch file run the .exe file multiple times. This, however, requires the use of the same text files to read from. The command prompt gives me the error that the ".txt could not be opened" (I assume from this that it is already open.)
I am trying to see if there is a way in a .bat file to system call to kill that specific text file. The suggestions I see online are to use 'taskkill notepad.exe', but that returns "invalid argument" because the program doesn't open Notepad to use the text file.
Any suggestions would be appreciated.
It sounds like your existing script fails because the first instance of the exe is still open when the second instance starts.
One thing worth trying (and this depends on the nature of the application you are invoking) is to start the executable using the START /WAIT /B ... command. This makes the command interpreter wait for the program to exit before it moves onto the next command, so as long as nothing else is locking the text files you should be OK to move onto the next command.

How to close a command window after batch file

I have a batch process in Win 8 that changes to a directory, runs MS Access to produce a text file ( that’s HTML with data, thought that fun), then starts an FTP process calling a text file that manages the upload. At the end of this I’m stuck with an open command window.
I’ve tried using “start” to start the ftp process, and I’ve played with using “exit” on the last line or not. Nothing is closing that window.
The File reads something like:
Cd\data
“c:\program files\office\msaccess” “c:\art\make_html_and_exit.mdb”
start ftp ftp.txt
exit
The window stays open.
As this must happen 4 times a day, I worry I'll annoy the user at the desk having to close the command window so often.
Yes, I know that this question has been covered before, but I can't get the window to close.
It is your "ftp-window" which is not closing. Right?
What are the contents of ftp.txt? The last line should be quit
By the way:
you should call ftp with
start ftp /s:ftp.txt
(see ftp /?)
This problem seems to have been caused by Logmein. When I was at the client’s site, the batch window closed fully. I then logged in remotely from a machine on the next desk and found the same failure to close.

getting returned results after running .BAT file

when i run a .BAT file, it displays a message but immediately closes the window
how i can i force it to keep the window open so that i can see the message reeturned?
One way is to conclude the batch file with the
PAUSE
command.
You can also wrap it another batch file that calls the original and then pauses:
FOO.BAT
PAUSE
This also works for read-only batch files and compiled executables.
An alternative is to execute this bat file from an already opened command prompt (shortcut: Windows Key + R, type cmd, press ENTER)

Resources