Solved Using a Batch file with a .com program

November 14, 2012 at 13:44:46
Specs: Windows XP, Intel 2.8GHz /3.43GB
I am working on automating a .com file. I think the bast way to do this is with a batch file, but I'm open to suggestions.

To run the .com file I type the name into the windows cmd prompt, then the file runs in its own environment, this is very confusing to me. I changed the color settings on my cmd window, when I run the .com file that section of the cmd window reverts to standard colors.

Once called the .com file asks for 3 user inputs. I can't figure out how to mimic the user. I've tried the standard redirection operators, but the inputs are not being passed.


See More: Using a Batch file with a .com program

Report •


✔ Best Answer
November 15, 2012 at 10:42:17
Sendkeys might handle it, but of course that is vbscript or visbasic. You can try this snippet just to see if this might work:
'==== begin vbscript trial-balloon snippet
set ws=createobject("wscript.shell")
ws.appactivate "Window title"
ws.sendkeys "some data"
'====== end vbscript

To try it, replace "Window title" with the actual window-title of your application, and
save the snippet with .vbs extension (like xxx.vbs). Start your application, then while it is running, in the command-prompt window run the script: xxx.vbs
You can also use the PID of the process in lieu of the window title.



#1
November 14, 2012 at 17:49:30
what is the .com file? and what op.sys type and version was it designed for?
Some executables don't observe standard-input, they read directly from devices (such as keyboard) and output directly to devices. Some support a form of "scripting" to enable non-interactive application. Or, you might be able to run it inside a wrapper, sending the input into the wrapper, like:
(echo test & echo two & echo third) | cmd.exe /c xx.com
but i kind of doubt if that would work...

Report •

#2
November 14, 2012 at 18:09:14
the .com file is one developed by my company for internal use years ago. I believe it was written in turbo pascal. It was written for windows operating systems, I don't know which one originally. I can run the file with manual inputs no problem, which leads me to believe it will only take keyboard inputs. I think I might need to simulate a keyboard, but I don't know where to start with that...

Report •

#3
November 15, 2012 at 02:17:56
Just to try, but nbrane explained the problems behind the curtain

echo.input1>> cmd.txt
echo.input2>> cmd.txt
echo.input3>> cmd.txt
prog.com < cmd.txt

By the way I don't think the program was developed in Turbo Pascal as TPC executables are suffixed .exe since Turbo Pascal 5 for DOS. Com executables were bound to early DOS versions.

Report •

Related Solutions

#4
November 15, 2012 at 07:16:59
You might try launching into COMMAND.COM before running any script, as I could see the switchover to another CLI interfering with the redirection.

How To Ask Questions The Smart Way


Report •

#5
November 15, 2012 at 10:42:17
✔ Best Answer
Sendkeys might handle it, but of course that is vbscript or visbasic. You can try this snippet just to see if this might work:
'==== begin vbscript trial-balloon snippet
set ws=createobject("wscript.shell")
ws.appactivate "Window title"
ws.sendkeys "some data"
'====== end vbscript

To try it, replace "Window title" with the actual window-title of your application, and
save the snippet with .vbs extension (like xxx.vbs). Start your application, then while it is running, in the command-prompt window run the script: xxx.vbs
You can also use the PID of the process in lieu of the window title.


Report •

#6
November 15, 2012 at 10:45:37
IVO: With prog.com < cmd.txt the program executes, but does not read the text file for inputs. The code is from the early 90s so it might have been written with DOS in mind.

Razor: I'm not sure what you mean. I've tried running directly form the command prompt.


Report •

#7
November 15, 2012 at 11:00:10
I only have access to matlab for writing code (it would be too easy if I could use visbasic). I think the bigger problem is finding the window title of the of my application. It runs within the cmd prompt window, but at the same time is not part on the window. I have a red background on the cmd prompt window, when I run the application the background changes to black. I'm not sure what that means. Do you think the window title is command prompt or something else that I can't see?

Report •

#8
November 15, 2012 at 11:09:57
In Win32, there are at least two different CLI environments. CMD, aka Command Prompt, which is (ab)used to do basic system administration. The other is COMMAND.COM, which emulates DOS' 16-bit environment, used for running programs written for DOS in the 80's and early 90's.

How To Ask Questions The Smart Way


Report •

#9
November 15, 2012 at 11:34:47
As for sendkeys and windowtitle, like i said, you can use process-id if you can't determine, or don't have a window-title to use. You can run tasklist to get the pid of the application: tasklist /fi "imagename eq xxxx.com"
(where xxx is the name of the .com pgm) then pull the pid from field two of the output.) OR, you could wrap your .com program into a batchfile that forces a title to be what you want using "title":
::=== batch snippet
title testing
xxxx.com
::== end
might work, i don't know... START will also do this, but it puts quotes around the title: START "testing" /max xxxx.com

Report •

#10
November 15, 2012 at 12:58:35
If this program is being run in the 16-bit environment, he will probably have to search for "ntvdm" instead of the actual program. You can test this out for yourself if you have a 32-bit version of Windows. Open EDIT.COM and try to find it in your process list.

How To Ask Questions The Smart Way


Report •

#11
November 15, 2012 at 17:14:01
Lol! that's exactly what i did, using both edlin.com and edlin.exe, and neither one showed up (directly) in tasklist, although I did obtain window titles: 16-bit was simply "edlin", 32-bit was C:\windows\system32\edlin, and neither one would swallow "sendkeys" input. Appactivate opened the window, but sendkeys sent nought into it. (somewhat off-topic... sorry) So i figure sendkeys was a dead-end.

Report •

#12
November 15, 2012 at 17:19:16
I was able to find the window name and try the ws sendkey code. This code did select the correct window, but did not type anything. I was able to make the code type in the command prompt.

When I use tasklist /fi "imagename eq xxxx.com" with my program name inserted, I get the message "INFO: No tasks running with the specified criteria. I get the same message when I try ntvdm in place of my program name I get the same message. I was unable to find anything with EDIT.COM (not sure if I was using it correctly).


Report •

#13
November 15, 2012 at 18:17:21
Those were just tests, (edit.com etc) to see what worked and didn't. I think you will have to re-write the program for current os, or try to find the source-code, locate the inputs, change them for file input, then recompile.
Model-Ts are just not well adapted to interstate highway conditions... :-(

Report •

#14
November 16, 2012 at 05:20:48
keycat06: I was unable to find anything with EDIT.COM (not sure if I was using it correctly).
That was directed towards nbrane, as your response to my initial response was a noncommittal shrug.

How To Ask Questions The Smart Way


Report •

#15
November 16, 2012 at 14:57:39
Thanks for your help guys.

Report •


Ask Question