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.
LVL 98
Lee W, MVPTechnology and Business Process AdvisorAsked:
Who is Participating?
 
PaulHewsCommented:
The only way I have seen how to do this is to mess around with VB's linker. The reason is that VB always will generate a GUI program, not a true console program.  

Here is the sample that does this from PlanetSourceCode

Updated: True Console App Compiler

 
 
* Build console applications using vb. This means the console opens in the exising dos boxes instead of opening a new window

When compiling the compiler reads a file if it has to build a console application!

This file is called 'modCompileOptions.bas'

* Also sample included If file is missing, it compiles as if this plugin is not installed.

* See the included sample for more information (after installing)

* Try both TRUE and FALSE to see the difference * Dont forget to install the new linker!

* Full Source included (Easyer code!)

INSTALLATION:

* RENAME LINK.EXE from you vb directory to VBLINK.EXE

* COPY LINK.EXE (FROM THE ZIP) to you vb directory

UNINSTALLATION:

* DELETE LINK.EXE from your vb directory

* RENAME VBLINK.EXE from you vb directory to LINK.EXE
 


http://www.planetsourcecode.com/xq/ASP/txtCodeId.13029/lngWId.1/qx/vb/scripts/ShowCode.htm
0
 
PaulHewsCommented:
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 
0
 
Lee W, MVPTechnology and Business Process AdvisorAuthor Commented:
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.
0
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
rspahitzCommented:
How about appactivate followed by sendkeys?
0
 
Lee W, MVPTechnology and Business Process AdvisorAuthor Commented:
I dabble and don't know what you are refferring to - can you clarify?
0
 
PaulHewsCommented:
>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...
0
 
Lee W, MVPTechnology and Business Process AdvisorAuthor Commented:
I dabble and don't know what you are refferring to - can you clarify?
0
 
rspahitzCommented:
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.
0
 
PaulHewsCommented:
Furthermore, doesn't @echo only work in batch mode?
0
 
rspahitzCommented:
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.
0
 
MoondancerCommented:
leew-->  2 things, what is your plan with this open question?  

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

Moondancer - EE Moderator
0
 
DanRollinsCommented:
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
0
 
Computer101Commented:
Comment from expert accepted as answer

Computer101
E-E Moderator
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.