Solved opening windows in batch

January 11, 2014 at 10:57:18
Specs: 7 pro, n/a
I'm having the below question, which is partly DOS command line related, but also Windows related:

Suppose I have a script, that performs this:

an_executable.exe inputfile1.txt
an_executable.exe inputfile2.txt
an_executable.exe inputfile3.txt

On purpose, the executable is unnamed here, and can be any Windows executable (Windows Media Player, MS Word, etc etc)

But, the file which is opened on every line, is a different file of course.

Now, suppose I actually run such a script, what seems:
- for every line, one occurance of the program is started, resulting in a series of windows being opened
- for certain EXEcutables, on opening each file,he is stopping the previous started Window, and thus ending with 1 EXE being opened

My question is : how do you control this behaviour ? How do you force that he is NOT opening a series of programs, but only one ?

Hi there.


See More: opening windows in batch

Report •


✔ Best Answer
January 17, 2014 at 13:27:18
If you use call instead of start the window will wait to proceed until notepad is closed.

call "" "notepad 1.txt"

::mike

message edited by mikelinus



#1
January 12, 2014 at 14:43:47
Not totally sure I understand what you are trying to do - maybe. As the program is being activated three times it could be attempting to re-run while it is still open, so try this (spaces important):

start /w "" "an_executable.exe inputfile1.txt"
start /w "" "an_executable.exe inputfile2.txt"
"an_executable.exe inputfile3.txt"

It is necessary to have quotes around the three files because they are more than 8 characters long. Start /w prevents the batch script continuing until the line has completed. The double quotes are because of a poorly documented feature, whereby what is first seen between quotes immediately after the start command is assumed to be a name.

As no paths are specified, this would all have to be done from the same place.

However, my batch filing knowledge is limited so I will flag this post up for transfer from the Windows 7 forum to the Programming forum. They might laugh at my attempts, also there is probably a much more elegant way of going about this.

Always pop back and let us know the outcome - thanks

message edited by Derek


Report •

#2
January 13, 2014 at 01:07:41
I'm not clear either about what's desired.

But if you want each exe to wait until the one before is finished:

notepad myfile.txt
notepad myfile2.txt

=====================
M2 Golden-Triangle


Report •

#3
January 13, 2014 at 08:25:40
So, two questions in the OP.

Q1) How to keep your script moving when you call an executable?
A1) Use the START command. As with anything CMD, there are a few gotchas. Documentation can be found by opening the Command Prompt and typing: START /?

Q2) How do you control if a document shows up in a new window, or an existing window?
A2) Calling a program from the command line starts a new instance of that application. Some applications have options/settings to control what happens when multiple instances are running, including passing the request along to an existing instance. Check your application's documentation.

How To Ask Questions The Smart Way


Report •

Related Solutions

#4
January 13, 2014 at 11:56:44
Keeping it simple [usually a good idea] to open a file using the exe which it's associated with:

::====== script starts here ===============
:: u2.bat 2014-01-14 2:44:17.14
@echo off & setLocal enableDELAYedeXpansioN

my.xls
my.txt
my.csv
my.jpg
::====== script ends here =================

=====================
M2 Golden-Triangle


Report •

#5
January 17, 2014 at 13:22:51
I must admit that the qeustion posted may have been clearer ... the problem is that windows remain open, not that the windows are opened all at once, or one by one.

The answer in post 3 is the direction I'm wanting to go : "Some applications have options/settings to control what happens when multiple instances are running, including passing the request along to an existing instance. Check your application's documentation."

The problem is of course, that that would depend on each of the applications.

I COULD propose the question differently, suppose I do this :

start /w "" "notepad 1.txt"
start /w "" "notepad 2.txt"

and, my goal would be this : Upon launching the second line - which only occurs after the application start by line 1, has been terminated, line 2 will be launched.

Now, the REAL problem is that the script that is launching all of this, is a controller script. It would be marking if the TXT file (in this case) is evaluated in some way. And then, when evaluated, the window showing file 1.txt may be closed.

This CAN be done by opening the same sort of application, for another file ... but, for some executables, he just leaves the application (in this case Notepad), open with file1.txt

And, I want to stop that program, but not by additionally closing it. That would be an extra action, which I need to repeat 1000 times, if my list is 1000 files.

I'm sure I'm not the first with such kind of ideas, but I'm struggling here. It works just fine with certain extensions, and really bad with most other extensions.

Hi there.


Report •

#6
January 17, 2014 at 13:27:18
✔ Best Answer
If you use call instead of start the window will wait to proceed until notepad is closed.

call "" "notepad 1.txt"

::mike

message edited by mikelinus


Report •

#7
January 17, 2014 at 13:35:39
I know, the issue is not that I don't know how to open them 1 by 1

I'm puzzled how to close them, also 1 by 1

Hi there.


Report •


Ask Question