Solved

Print in DOS Prompt

Posted on 2001-07-01
13
225 Views
Last Modified: 2012-06-27
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.
0
Comment
Question by:Lee W, MVP
  • 4
  • 3
  • 3
  • +3
13 Comments
 
LVL 38

Expert Comment

by:PaulHews
ID: 6243894
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
 
LVL 95

Author Comment

by:Lee W, MVP
ID: 6247154
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
 
LVL 38

Accepted Solution

by:
PaulHews earned 174 total points
ID: 6247206
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
 
LVL 22

Expert Comment

by:rspahitz
ID: 6249898
How about appactivate followed by sendkeys?
0
 
LVL 95

Author Comment

by:Lee W, MVP
ID: 6249932
I dabble and don't know what you are refferring to - can you clarify?
0
 
LVL 38

Expert Comment

by:PaulHews
ID: 6249968
>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
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 
LVL 95

Author Comment

by:Lee W, MVP
ID: 6250065
I dabble and don't know what you are refferring to - can you clarify?
0
 
LVL 22

Expert Comment

by:rspahitz
ID: 6250182
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
 
LVL 38

Expert Comment

by:PaulHews
ID: 6250230
Furthermore, doesn't @echo only work in batch mode?
0
 
LVL 22

Expert Comment

by:rspahitz
ID: 6250287
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
 
LVL 1

Expert Comment

by:Moondancer
ID: 6900670
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
 
LVL 49

Expert Comment

by:DanRollins
ID: 7140049
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
 
LVL 1

Expert Comment

by:Computer101
ID: 7178811
Comment from expert accepted as answer

Computer101
E-E Moderator
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

759 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now