Problem getting exe to recognize filename from batch file

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
CWK
Posts: 9
Joined: 18 Nov 2013 20:18

Problem getting exe to recognize filename from batch file

#1 Post by CWK » 18 Nov 2013 20:36

This is in Windows 7 but I hope XP will apply.

Am trying to use a .bat file to supply answers to a series of prompts that come from an .exe file (compiled Fortran; don't have the un-compiled code and don't know the compiler used).

The form of the batch file is:
(echo w.in <this is name of input data file (which already exists)
echo myname <this is a text string
echo printheader <this is a text string
echo w.out <this is name of desired output file
...etc... < some more echoed input to prompts
echo 1) | myprogram.exe <last echo and pipe to launch myprogram
pause

Running the batch file launches myprogram and it seems to receive the first four lines of prompted input (w.in through w.out), but then it returns a long error message, which seems to indicate that it has tried but could not open w.in. The error message is as follows:
"open: No such file or directory
apparent state: unit 1 named d:watch.in
lately reading sequential formatted external IO
2 [sig] myprogram 6732 open_stackdumpfile: Dumping stack trace to myprogram.exe.stackdump"
File watch.in is present at d:, so as far as I can tell the location does not seem to be the problem.
Does anyone have any ideas what might be going on and how to get around it? Thx

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Problem getting exe to recognize filename from batch fil

#2 Post by foxidrive » 18 Nov 2013 21:32

AutoIt might help you input the lines.

We need more information to help - the exact input lines being used, the batch file, and a copy of the executable to test with would all help.

CWK
Posts: 9
Joined: 18 Nov 2013 20:18

Re: Problem getting exe to recognize filename from batch fil

#3 Post by CWK » 19 Nov 2013 16:48

Thanks, have downloaded AutoIt and am evaluating for use.
In the meantime, being new to this forum and with only modest experience in other forums, it is not clear to me how to post a copy of the executable.

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Problem getting exe to recognize filename from batch fil

#4 Post by foxidrive » 20 Nov 2013 03:06

An easy way is to post the data in a zip file to dropbox and then post the link.

CWK
Posts: 9
Joined: 18 Nov 2013 20:18

Re: Problem getting exe to recognize filename from batch fil

#5 Post by CWK » 20 Nov 2013 18:53

Posted this response about 8 hours ago but don't find it in thread, so here goes again:
Three files are at dropbox links as follows:
1) https://dropfile.external.slb.com/cgi-b ... d=vSMiTObm
This is the exe (a public domain code)
2) https://dropfile.external.slb.com/cgi-b ... d=g3NdLrCv
This is the input file to the exe

The third link will follow in next post.

CWK
Posts: 9
Joined: 18 Nov 2013 20:18

Re: Problem getting exe to recognize filename from batch fil

#6 Post by CWK » 20 Nov 2013 18:54

3) https://dropfile.external.slb.com/cgi-b ... d=p0aznzkT
This is the batch file I hope will run the exe. The first echo supplies the name of the input file. The exe seems to start, then abort after the fourth echo input, when it tries to open the input file and cannot find it. Please note that the fifth echo ("") is an attempt to simple enter {Return} with no text or number; I don't know that this is the correct way to do that, but have not been able to test it because the process aborts before trying it.

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Problem getting exe to recognize filename from batch fil

#7 Post by foxidrive » 20 Nov 2013 21:35

Those file links require us to register and create an account.

If you use dropbox then they are shared without us needing to register to the service. You can also zip the files up into one link, too.

CWK
Posts: 9
Joined: 18 Nov 2013 20:18

Re: Problem getting exe to recognize filename from batch fil

#8 Post by CWK » 21 Nov 2013 13:14

Sorry, but when dropbox asks me to enter a valid name or email address, what do I enter?

ShadowThief
Expert
Posts: 1167
Joined: 06 Sep 2013 21:28
Location: Virginia, United States

Re: Problem getting exe to recognize filename from batch fil

#9 Post by ShadowThief » 21 Nov 2013 14:07

A valid name or email address.

The service is free, but you still have to register.

CWK
Posts: 9
Joined: 18 Nov 2013 20:18

Re: Problem getting exe to recognize filename from batch fil

#10 Post by CWK » 21 Nov 2013 17:58

I had registered. Dropbox was asking for your email address. Finally figured out how to get and send a link.
Hope it works.

https://www.dropbox.com/s/35xegnx6il6l4 ... ction.zipx

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Problem getting exe to recognize filename from batch fil

#11 Post by foxidrive » 21 Nov 2013 20:59

Here is a proof of operation using sendkeys. You would need to let the PC run and not interrupt the keyboard or window focus for this to work.

The set lines from a to k are the lines of input and then it calls the routine to create the VBS script, and launches the watch24.exe and the script then runs to enter the information.

There could be a number of enhancements depending on which fields actually change and which can be constant, and how you have the data to be input.
It could be read from a file, for example, and between each run it could store the data files, and then run again.

Code: Select all

@echo off

set a=
set b=CWK
set c=header
set d=
set e=
set f=0
set g=230
set h=1,220
set i=1
set j=0
set k=

call :vbs

start "" /b "watch24.exe"
cscript /nologo "%temp%\watch.vbs"
cls
echo check watch.out
pause
goto :eof

:vbs
(
echo set fso=CreateObject("WScript.Shell"^)
echo wscript.sleep 50
echo fso.SendKeys "%a%{Enter}"
echo wscript.sleep 50
echo fso.SendKeys "%b%{Enter}"
echo wscript.sleep 50
echo fso.SendKeys "%c%{Enter}"
echo wscript.sleep 250
echo fso.SendKeys "%d%{Enter}"
echo wscript.sleep 250
echo fso.SendKeys "%e%{Enter}"
echo wscript.sleep 50
echo fso.SendKeys "%f%{Enter}"
echo wscript.sleep 50
echo fso.SendKeys "%g%{Enter}"
echo wscript.sleep 50
echo fso.SendKeys "%h%{Enter}"
echo wscript.sleep 50
echo fso.SendKeys "%j%{Enter}"
echo wscript.sleep 50
echo fso.SendKeys "%k%{Enter}"
)> "%temp%\watch.vbs"


CWK
Posts: 9
Joined: 18 Nov 2013 20:18

Re: Problem getting exe to recognize filename from batch fil

#12 Post by CWK » 21 Nov 2013 22:26

Thanks, foxdrive, will give this a try and get beck to you if having problems.

CWK
Posts: 9
Joined: 18 Nov 2013 20:18

Re: Problem getting exe to recognize filename from batch fil

#13 Post by CWK » 22 Nov 2013 11:06

Have been studying the script to understand its components and how it flows and am curious:

(a) what is the function of the carat (^) in CreateObject("WScript.Shell"^)

(b) I gather that "echo check watch.out" is checking for the presence of watch.out, but in doing internet searches for "check filename" as a command, I can't find it anywhere. Just finding chkdsk.

Thx

Squashman
Expert
Posts: 4488
Joined: 23 Dec 2011 13:59

Re: Problem getting exe to recognize filename from batch fil

#14 Post by Squashman » 22 Nov 2013 11:42

The closing parenthesis needs to be escaped by the batch file for it to echo to the VBS file.

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Problem getting exe to recognize filename from batch fil

#15 Post by foxidrive » 22 Nov 2013 18:40

CWK wrote:Have been studying the script to understand its components and how it flows and am curious:

(a) what is the function of the carat (^) in CreateObject("WScript.Shell"^)

(b) I gather that "echo check watch.out" is checking for the presence of watch.out, but in doing internet searches for "check filename" as a command, I can't find it anywhere. Just finding chkdsk.



squashman has told you the purpose of the caret - and it is escaped because within a loop, a regular bracket would be taken as the (premature) ending of the loop.
It is a quirk with batch code that only the closing brackets need to be escaped.

"echo check watch.out" is merely a line printed to the console. I should have written "echo check the file watch.out etc for the results"

Post Reply