Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Simulating input without actually typing

Status
Not open for further replies.

akelabanda

Programmer
Dec 19, 2001
61
IN
Hi

I am trying to simulate keystrokes in my program
without actually typing a character and "\n".

=============================
#!/usr/bin/perl

@test = `pkgadd -d /export/home/raj/BOLTpget.pkg`;
=============================

This will display

=============================
The following packages are available:
1 BOLTpget pkg-get
(all) 1.9.5

Select package(s) you wish to process (or 'all' to process
all packages). (default: all) [?,??,q]:
=============================

Now I want to have a "q" and "\n" input automatically
such that the program does not wait for manual input.

Ideally I want to read this screen into a list (@output)
for further processing.

Please help.

Regards
Rajeev
 
If your script doesn't require any other manual inputs, the normal way to do this is with input redirection. Create a file (/tmp/q.txt) containing just a q and a newline. Then execute your script as:

myscript.pl < /tmp/q.txt

or

cat /tmp/q.txt | myscript.pl

 
Can you use the -n flag to run pkgadd in non-interactive mode? This would be much easier than waiting on a terminal prompt if all you want to do is quit when you are done.

jaa
 
Code:
Windows Script File

<Job Id=&quot;WshShell&quot;>
<script language=PerlScript>
 $WshShell = $WScript->CreateObject(&quot;WScript.Shell&quot;);
 $WshShell->Run(&quot;notepad&quot;, 5);
 $WshShell->AppActivate(&quot;Untitled - Notepad&quot;);
 my $message = &quot;Hello from PerlScript!\n&quot;;
 for($i=0; $i < length($message); $i++) {
  $char = substr($message, $i, 1);
  $WScript->Sleep(100);
  $WshShell->SendKeys($char);
 }
</script>
</job>
---------------------------------------
wmail.jpg


someone knowledge ends where
someone else knowledge starts
 
sampsonr
========
Thanx for your help. This is one way of doing it. But
I would like to avoid using a file for this purpose.
Is there any other way ?

justice41
=========
Thx. I want to capture the 1st screen. That's the reason
I dont use the -n option.

Thanks in advance for your help.

Regards
Rajeev
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top