Solved

Print in DOS Prompt

Posted on 2001-07-01
13
270 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 96

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
SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

 
LVL 22

Expert Comment

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

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
 
LVL 96

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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses
Course of the Month5 days, 10 hours left to enroll

626 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