Link to home
Start Free TrialLog in
Avatar of Lee W, MVP
Lee W, MVPFlag for United States of America

asked on

Print in DOS Prompt

I'm trying to write a 32bit command line (for WinNT/2K/9X) program and need to know how to print messages/results to the screen.  For example, I create "MYPROGRAM.EXE" and the following commands are entered on the command line:

C:\>MYPROGRAM /PRINT
RESULTS PRINTED HERE
C:\>

I guess I'm looking for a VB version of QuickBASIC/BASIC "PRINT " statement.  But as I understand it, I need an object for that to work.  So what object would I use, if I would use one at all.
Avatar of PaulHews
PaulHews
Flag of Canada image

You want a console program that outputs to StdOut.
Here's a sample console project from freevbcode:

http://www.freevbcode.com/ShowCode.Asp?ID=1265 
Avatar of Lee W, MVP

ASKER

Not quite what I was looking for - the sample code you referred me to does ALMOST what I'm looking for - but I don't want it to open another DOS window - this won't allow the utility I'm trying to make to be compatible with batch files.

I can read input from the command line with command(), but I want a simple way to print "results" to the same command prompt window.
ASKER CERTIFIED SOLUTION
Avatar of PaulHews
PaulHews
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
How about appactivate followed by sendkeys?
I dabble and don't know what you are refferring to - can you clarify?
>How about appactivate followed by sendkeys?

I thought about that, but there are some problems with that.

1. Generating output with SendKeys... To avoid the command interpreter catching the sent keys as commands, you would have to execute echo statements.  You would have to execute the @echo off to turn off the actual typing of the commands.  It would be tricky and it probably wouldn't look nice, but it might work.

2. Reliably catching the original console window and the reliability of sendkeys...
I dabble and don't know what you are refferring to - can you clarify?
I think I agree with PaulHews but since you asked:

-------------
AppActivate

Activates an application window.

Syntax

AppActivate title[, wait]

-------------
SendKeys

Sends one or more keystrokes to the active window as if typed at the keyboard.

Syntax

SendKeys string[, wait]
-------------

In other words, once you find the name of the DOS window, you can have VB tell windows to make it the active window (sort of a "bring to front") with something like:
   AppActivate "MD-DOS"

Once this app has the "focus" you can use VB to send it keystrokes:

   SendKeys "This is my message"

However, as PaulHews indicated, there are problems with this because the DOS window will try to interpret your messages as commands unless you tell it to simply display the text, in which case you'd have to deal with issues of special characters.  You could try:

   SendKeys "@Echo This is my message" & vbcrlf

But this will give you trouble:

   SendKeys "@Echo Is 3 < 5? Yes!" & vbcrlf

The special characters that will cause trouble include:
   < > / \ | : ( ) + =

and maybe a few more.
Furthermore, doesn't @echo only work in batch mode?
I just tried this sendkeys within Win2000 and it seems very flaky.  It seems to be rejecting every key sent!

P.S.
The "@echo" doesn't cause problems at the DOS command line.
Avatar of Moondancer
Moondancer

leew-->  2 things, what is your plan with this open question?  

You have points awaiting your comments here:
https://www.experts-exchange.com/jsp/qManageQuestion.jsp?ta=win2k&qid=20156345

Moondancer - EE Moderator
Hi leew,
It appears that you have forgotten this question. I will ask Community Support to close it unless you finalize it within 7 days. I will suggest to:

    Accept PaulHews's comment(s) as an answer.

leew, if you think your question was not answered at all or if you need help, you can simply post a new comment here.  Community Support moderators will follow up.

EXPERTS: If you disagree with that recommendation, please post an explanatory comment.
==========
DanRollins -- EE database cleanup volunteer
Comment from expert accepted as answer

Computer101
E-E Moderator