Solved

Print in DOS Prompt

Posted on 2001-07-01
13
235 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

911 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

17 Experts available now in Live!

Get 1:1 Help Now