Passing or Piping commands into a dos window

bizygha

Junior Member
Oct 24, 2013
11
0
61
Is it possible in windows to interact with a previously open DOS session, and pass commands into that session?

I have a dos program running in that session, and don't have the source code to that program, so I can't modify it. It runs in a dos session, and sits there waiting for commands, that can be typed in by hand. I want to send commands to that program and read its output in an automated way.


Is something like this possible?
 

EagleKeeper

Discussion Club Moderator<br>Elite Member
Staff member
Oct 30, 2000
42,591
5
0
To pipe to an output file the command Window uses >> output.txt

Try creating an input file of commands.
In the command windows when you type in the application name follow it with << input.txt

That may work
 

nickbits

Diamond Member
Mar 10, 2008
4,122
1
81
For a bit more control, it's easy to do via programming in .NET/C#. Create a Process object and tap into StandardOutput and StandardInput.
Might be possible to do something with powershell but I haven't played around with that.
 

takeru

Golden Member
Jan 1, 2002
1,205
3
81
are you passing arguments to it at execution, or are you passing commands to it while the program is running already? i would assume running already since you said it sits there waiting for commands? you can try what eagle said to capture the output, and use autoit to grab focus of the dos window and feed it commands, then read/parse the output.txt for the response.
 
Last edited:

bizygha

Junior Member
Oct 24, 2013
11
0
61
To pipe to an output file the command Window uses >> output.txt

Try creating an input file of commands.
In the command windows when you type in the application name follow it with << input.txt

That may work

Thanks, I tried this, and i get a '<< was unexpected at this time' message. I tried with a single '<' but that seemed to fail. I can get the >> output.txt to work though. I'm not sure I can use a static file like anyway that because I want to interact with the program at its command prompt. Goes something like this--

C:\> Analyzer.exe

Analyzer> (I type a command here)

(I get message with output status)

(and then back to program's prompt.)

(at this point I read an output file that is produced, and based on the results come up with a new command.)

Analyzer> ( I type that new command here. and the cycle repeats)
 
Last edited:

EagleKeeper

Discussion Club Moderator<br>Elite Member
Staff member
Oct 30, 2000
42,591
5
0
There is no way to send data to the program because it is designed for direct user input via stdin.

You can trick it to think stdin is a data file, but that is it.

The OS sets up input when app starts. After that, the app is on autopilot based on the input data.
 

EagleKeeper

Discussion Club Moderator<br>Elite Member
Staff member
Oct 30, 2000
42,591
5
0
Without source, you are SOL.
Write a replacement application is about the only solution.

Some may try to break open the applican, but that is very iffy.

Best to create specs based on what the app is doing and then write an app that has the enhancements you need.
 

Fallen Kell

Diamond Member
Oct 9, 1999
6,063
437
126
Thanks, I tried this, and i get a '<< was unexpected at this time' message. I tried with a single '<' but that seemed to fail. I can get the >> output.txt to work though. I'm not sure I can use a static file like anyway that because I want to interact with the program at its command prompt. Goes something like this--

C:\> Analyzer.exe

Analyzer> (I type a command here)

(I get message with output status)

(and then back to program's prompt.)

(at this point I read an output file that is produced, and based on the results come up with a new command.)

Analyzer> ( I type that new command here. and the cycle repeats)


You need something like "expect" for windows.... Do not know if it exists or not. You might be able to simply install Cygwin and run your application that way and gain expect.
 
Last edited:

Ken g6

Programming Moderator, Elite Member
Moderator
Dec 11, 1999
16,284
3,905
75
It sounds like you want an "automation" tool. There are various ways of doing this. It generally helps if you can get data sent over TCP, such as by opening a TELNET terminal connection to your own system.

If that's not possible in this case - and I suspect it's not - there are direct Windows automation tools. This Python recipe looks interesting if your application has a command prompt - meaning it doesn't use CURSES to draw nice graphics. Even in that case you might be able to do something.
 

takeru

Golden Member
Jan 1, 2002
1,205
3
81
There is no way to send data to the program because it is designed for direct user input via stdin.

You can trick it to think stdin is a data file, but that is it.

The OS sets up input when app starts. After that, the app is on autopilot based on the input data.

you can, with autoit using send key commands. he can try what i wrote above. autoit is built to handle automating manual processes. typing in cmd is easy with it, and parse the output txt file with autoit, and depending on what result you expect, refocus to the cmd again and feed it more commands.
 

bizygha

Junior Member
Oct 24, 2013
11
0
61
According to the Cygwin website, I would be suprised if this would work. Do you still think this may work?

Best to create specs based on what the app is doing and then write an app that has the enhancements you need.

This Python recipe looks interesting if your application has a command prompt - meaning it doesn't use CURSES to draw nice graphics. Even in that case you might be able to do something.

you can, with autoit using send key commands. he can try what i wrote above. autoit is built to handle automating manual processes. typing in cmd is easy with it, and parse the output txt file with autoit, and depending on what result you expect, refocus to the cmd again and feed it more commands.

Thanks for the suggestions. Initially I didn't realize there wouldn't be 'standard' method embedded into the OS, (Windows), to do it, (unlike linux), although I had an inkling. I contacted the app vendor since remaking this app would probably take me years, anyway they decline to provide this functionality. I am not familiar with Python or AutoIt, I will start looking into them.
 

EagleKeeper

Discussion Club Moderator<br>Elite Member
Staff member
Oct 30, 2000
42,591
5
0
you can, with autoit using send key commands. he can try what i wrote above. autoit is built to handle automating manual processes. typing in cmd is easy with it, and parse the output txt file with autoit, and depending on what result you expect, refocus to the cmd again and feed it more commands.

AutoIt may not work as you think.
My concern is the OP is not using a Windows program. It is a "DOS" type program that is being run in a Command Window.

From the AutoIt site
AutoIt v3 is a freeware BASIC-like scripting language designed for automating the Windows GUI and general scripting. It uses a combination of simulated keystrokes, mouse movement and window/control manipulation in order to automate tasks in a way not possible or reliable with other languages (e.g. VBScript and SendKeys).
 

takeru

Golden Member
Jan 1, 2002
1,205
3
81
AutoIt may not work as you think.
My concern is the OP is not using a Windows program. It is a "DOS" type program that is being run in a Command Window.

From the AutoIt site

yes i know. another poster from here awhile back wanted to target a cmd window also:
http://forums.anandtech.com/showthread.php?t=2318462

it is possible to target the window by title and start messing with it.

example of changing cygwin window titles:
http://heath.hrsoftworks.net/archives/000139.html
 

BoberFett

Lifer
Oct 9, 1999
37,563
9
81
AutoIt may not work as you think.
My concern is the OP is not using a Windows program. It is a "DOS" type program that is being run in a Command Window.

From the AutoIt site

It doesn't matter whether it's a command window or a DOS program running in a window, that window still has a handle and given focus and interacted with like any other window.
 

serpretetsky

Senior member
Jan 7, 2012
642
26
101
slightly off-topic. I've seen people here more than once refer to DOS programs or going into DOS to run commands. Seeing as how this is 2013, I'm assuming everyone is referring to the command prompt, and command line programs, correct?
 

takeru

Golden Member
Jan 1, 2002
1,205
3
81

EagleKeeper

Discussion Club Moderator<br>Elite Member
Staff member
Oct 30, 2000
42,591
5
0
It doesn't matter whether it's a command window or a DOS program running in a window, that window still has a handle and given focus and interacted with like any other window.


With a regular window, you can send a WM_CHAR event message that gets picked up and if designed for, handled.

You are stating that the CMD window will take a WM_CHAR event message and pass it to stdin?




As to the OP problem; he still seems to be having to have the human in the loop making decisions about what information he wants to feed the program based on outs.

Unless he can define a table of output->input options that is consistent; automating should not help him.
 
Last edited:

bizygha

Junior Member
Oct 24, 2013
11
0
61
Sorry, I may have given the wrong impression. Outside of the initial setup, there is no human interaction necessary. The 'analyzer' is wrapped in an optimizing function. Every action taken by the 'optimizer' depends on the results of the analyzer--(what is meant by it not being static).
 
sale-70-410-exam    | Exam-200-125-pdf    | we-sale-70-410-exam    | hot-sale-70-410-exam    | Latest-exam-700-603-Dumps    | Dumps-98-363-exams-date    | Certs-200-125-date    | Dumps-300-075-exams-date    | hot-sale-book-C8010-726-book    | Hot-Sale-200-310-Exam    | Exam-Description-200-310-dumps?    | hot-sale-book-200-125-book    | Latest-Updated-300-209-Exam    | Dumps-210-260-exams-date    | Download-200-125-Exam-PDF    | Exam-Description-300-101-dumps    | Certs-300-101-date    | Hot-Sale-300-075-Exam    | Latest-exam-200-125-Dumps    | Exam-Description-200-125-dumps    | Latest-Updated-300-075-Exam    | hot-sale-book-210-260-book    | Dumps-200-901-exams-date    | Certs-200-901-date    | Latest-exam-1Z0-062-Dumps    | Hot-Sale-1Z0-062-Exam    | Certs-CSSLP-date    | 100%-Pass-70-383-Exams    | Latest-JN0-360-real-exam-questions    | 100%-Pass-4A0-100-Real-Exam-Questions    | Dumps-300-135-exams-date    | Passed-200-105-Tech-Exams    | Latest-Updated-200-310-Exam    | Download-300-070-Exam-PDF    | Hot-Sale-JN0-360-Exam    | 100%-Pass-JN0-360-Exams    | 100%-Pass-JN0-360-Real-Exam-Questions    | Dumps-JN0-360-exams-date    | Exam-Description-1Z0-876-dumps    | Latest-exam-1Z0-876-Dumps    | Dumps-HPE0-Y53-exams-date    | 2017-Latest-HPE0-Y53-Exam    | 100%-Pass-HPE0-Y53-Real-Exam-Questions    | Pass-4A0-100-Exam    | Latest-4A0-100-Questions    | Dumps-98-365-exams-date    | 2017-Latest-98-365-Exam    | 100%-Pass-VCS-254-Exams    | 2017-Latest-VCS-273-Exam    | Dumps-200-355-exams-date    | 2017-Latest-300-320-Exam    | Pass-300-101-Exam    | 100%-Pass-300-115-Exams    |
http://www.portvapes.co.uk/    | http://www.portvapes.co.uk/    |