Solved

Sending data to a dos program

Posted on 2011-09-22
8
224 Views
Last Modified: 2012-05-12
Hello everyone,

I have a program that runs lets call it testrunner, that excepts 2 parameters, databasename and userid.  So for example

testrunner -d test -u testuser

It then prompts for a password, there is no parameter for it in the command line.

I need to call testrunner from a service, but I'm not sure if there is a way to run it, and then send the keystrokes to type hte password in when it prompts for it.

Any idea's?

Thanks!

DJB
0
Comment
Question by:dbridle
[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
8 Comments
 
LVL 69

Accepted Solution

by:
Qlemo earned 250 total points
ID: 36578948
You can try if
cmd /c echo password | testrunner -d test -u testuser
works. If not, you will have to use the VB Sendkey method, applied to the application/cmd window to send the key strokes required for the password, combined with some sleep time to allow for the password prompt.
0
 

Author Comment

by:dbridle
ID: 36578966
Thanks for your response, I will give the cmd /c command a shot,
0
 
LVL 43

Expert Comment

by:Steve Knight
ID: 36579048
also if not there is a great free app called autoit which you can use to send keys, mouse clicks, wait for things to appear first etc.  yoou write this as a simple tect file script like batch file or vbscript and then it can compile it into an exe.

So you could have (pseudo copde)

run program testrunner etc.
Wait for window testrunner to appear
type in password
exit

the app would continue to run and accept other keystrokes if needed.  if you pipe the password in it will accept no real keystrokes

also as you compile it into an exe the password is not there in plain text

can help with links s syntax if needed... Once on pc but there are loads of example scripts with it when you download anyway.


Steve
0
Forrester Webinar: xMatters Delivers 261% ROI

Guest speaker Dean Davison, Forrester Principal Consultant, explains how a Fortune 500 communication company using xMatters found these results: Achieved a 261% ROI, Experienced $753,280 in net present value benefits over 3 years and Reduced MTTR by 91% for tier 1 incidents.

 
LVL 83

Expert Comment

by:CodeCruiser
ID: 36582217
You can also try another approach using the Process class. Find example code on below link

http://stackoverflow.com/questions/6969731/get-output-into-my-application-from-another-java-console

The code only shows reading output from the console app but you can use the same principle of streams to write text as input to console app(e.g p.StandardInput.WriteLine("Password"))
0
 
LVL 11

Expert Comment

by:paultomasi
ID: 36590485
Have you tried simple redirection as in the following?

   echo password | testrunner -d test -u testuser

or:

   echo password | (testrunner -d test -u testuser)


You could also try it without the spaces around the '|' (pipe symbol).
0
 
LVL 11

Expert Comment

by:paultomasi
ID: 36590502
You might even prefer to get the password from a file. Suppose your password is stored in a text file named PASSWORD.TXT

You can then use the following:

   testrunner -d test -u testuser <password.txt

or:

   (testrunner -d test -u testuser) <passowrd.txt

0
 
LVL 43

Expert Comment

by:Steve Knight
ID: 36591922
I'm sure I hit submit on a comment like this last night, Paul I'm surprised you didn't suggest using ADS to hide the password like in your answer from before which I keep for my info here... I hadn't seen it used before BillDL and you mentioned it in this question and has come in handy on a number of occasions since -- no-one has worked out where the password comes from :-)

http://scripts.dragon-it.co.uk/links/batch-password1
( http://www.experts-exchange.com/OS/Microsoft_Operating_Systems/MS_DOS/Q_25000620.html?cid=1133#a26130150 )

Steve
0
 
LVL 11

Expert Comment

by:paultomasi
ID: 36592435
Ah, Steve (dragon-it), I never did reply to that thread.... I was playing about with ADS at the time and never finished my write-up on it as I digressed onto something else (as we do).

I've only got a few more things I want to accomplish in DOS at the moment and as they all involve embedded assembly code I've been dragging my heels for far too long now.... All will be revealed in the very near future.

I'm not sure whether the asker wanted to 'hide' the password from the user or whether he merely wanted a non-user assisted solution to logging into his program.

The solutions above only address the non-user assisted methods for getting a password into a program. They may not even work depending on whther the program flushes the keyboard buffer prior to fetching keystrokes (as you probably know quite well).

Sure, ADS, and even redirection can be used to hide a password from a casual user to some extent but i don't think that's the issue in this case. I could be wrong though.

:)


dbridle

Just so as you know what Steve is refering to, I wrote this comment (under the peened name t0t0) quite some time ago. It deals with hiding and retrieving a password using ADS:

http://www.experts-exchange.com/OS/Microsoft_Operating_Systems/MS_DOS/Q_25000620.html?cid=1133#a26130150
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

733 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