Sign in to follow this  
Followers 0
matthewdowney20

Print to command line?

6 posts in this topic

Hey everyone,

I am currently writing a command line application, and am having trouble with making it print back to the command line. Here is what I tried initially:

myprogram.au3

$MyCommand = 'dir'
Run(@ComSpec & " /c " & $MyCommand, @SystemDir, @SW_Show)
Run(@ComSpec & " /c @echo off && echo Command completed successfully. && @echo on", @SystemDir, @SW_Show)

Then I compiled it and ran it via the command line:

(each code box represents a command line)

C:\Users\Matthew>myprogram.au3
C:\Users\Matthew>

Opens new shell

Volume in drive C has no label.
Volume Serial Number is 0287-990C
Directory of C:\Users\Matthew
08/06/2012 07:37 PM <DIR>        .
08/06/2012 07:37 PM <DIR>        ..
07/15/2012 09:20 AM <DIR>        .idlerc
08/12/2012 05:13 PM <DIR>        .VirtualBox
09/10/2011 04:00 PM  2,050,902,016 BT5-GNOME-32.iso
07/12/2012 10:17 AM <DIR>        Contacts
08/13/2012 03:39 PM <DIR>        Desktop
08/13/2012 01:40 PM <DIR>        Documents
08/12/2012 05:12 PM <DIR>        Downloads
07/12/2012 10:17 AM <DIR>        Favorites
07/13/2012 06:22 PM <DIR>        Links
07/25/2012 11:51 PM <DIR>        Music
08/11/2012 02:17 AM          442 openvpn-connect.json
08/13/2012 12:33 PM      12,655 ovpntray.log
05/25/2012 03:51 AM  4,167,214,806 People In Motion.mp4
07/12/2012 10:17 AM <DIR>        Pictures
07/12/2012 10:17 AM <DIR>        Saved Games
08/12/2012 05:16 PM          899 SciTE.session
07/12/2012 10:17 AM <DIR>        Searches
07/14/2012 05:42 PM  728,150,016 ubuntu-10.04.4-desktop-i386.iso
07/15/2012 10:18 AM <DIR>        Videos
08/11/2012 06:16 PM <DIR>        VirtualBox VMs
             6 File(s) 6,946,280,834 bytes
             16 Dir(s) 1,814,325,567,488 bytes free

Once finished listing files in my directory that exits and

Opens new shell

The command completed successfully.

and that window closes immediated (I made sure it was saying that by appending '&& pause' to the end of the echo commands).

The output I am looking for is the same thing, but in one window, like this:

C:\Users\Matthew>myprogram
*output of dir command*
The command completed successfully
C:\Users\Matthew>

Share this post


Link to post
Share on other sites



why in the world do you need to do this? I'm asking out of simple curiosity. One could make a GUI that does what you are doing so I'm trying to understand your motive. If anything I may learn something. Thanks.

I was actually also looking for a way to do this recently, I've been getting tired of using the RunAs command to run things as admin in the windows command prompt so I was thinking of making a little application that could be called from the command line and would perform the specified command as administrator, and I wanted it to do this so that it would execute in the same shell. I'm sure there are tons of other uses for this too.

Now I'm intrigued :D Any ideas guys?

Share this post


Link to post
Share on other sites

Please do not double-post. You already have a thread with the same title


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

Please do not double-post. You already have a thread with the same title

I'm sorry! Could you delete the other post? I tried but I don't have permission to. The other one was a half finished version of this that I accidentally posted and then could not delete.

Edited by matthewdowney20

Share this post


Link to post
Share on other sites

You can't delete a thread. Just ignore it for now.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0