CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
quick question regarding sending keys to system command

 



testbot
New User

Oct 31, 2012, 10:06 AM

Post #1 of 4 (1030 views)
quick question regarding sending keys to system command Can't Post

thanks for reading this. thanks even more if you have the answer haha

not sure why i can't figure this out but how would i feed line returns or input to an executed command.

if you're familiar with nmap then you might know that while it's running you can hit the enter key and it will return the status.

i'm attempting to run nmap from within a perl script and i want to be able to feed it line returns when the enter key is pressed to get status updates.

i'm currently using:

Code
$command = "nmap -blah -blah" 
system($command);


thanks!


FishMonger
Veteran / Moderator

Oct 31, 2012, 11:24 AM

Post #2 of 4 (1025 views)
Re: [testbot] quick question regarding sending keys to system command [In reply to] Can't Post


Quote
if you're familiar with nmap then you might know that while it's running you can hit the enter key and it will return the status.

That is not always true. It depends on 3 factors 1) the system it's being run on, 2) the version of nmap and 3) the version of pcap.

What you want to do can't be done via the system function because it simply forks a child process and blocks the parent until the command completes and then returns the exit code to the parent. What you want to achieve might be possible via Expect, but I've never bothered to test it.

man expect - http://linux.die.net/man/1/expect
Expect.pm perl module - http://search.cpan.org/~rgiersig/Expect-1.21/Expect.pod

My recommendation would be to use the Nmap::Scanner module.
http://search.cpan.org/~maxschube/Nmap-Scanner-1.0/lib/Nmap/Scanner.pm


testbot
New User

Oct 31, 2012, 1:42 PM

Post #3 of 4 (1018 views)
Re: [FishMonger] quick question regarding sending keys to system command [In reply to] Can't Post


In Reply To

Quote
if you're familiar with nmap then you might know that while it's running you can hit the enter key and it will return the status.

That is not always true. It depends on 3 factors 1) the system it's being run on, 2) the version of nmap and 3) the version of pcap.

What you want to do can't be done via the system function because it simply forks a child process and blocks the parent until the command completes and then returns the exit code to the parent. What you want to achieve might be possible via Expect, but I've never bothered to test it.

man expect - http://linux.die.net/man/1/expect
Expect.pm perl module - http://search.cpan.org/~rgiersig/Expect-1.21/Expect.pod

My recommendation would be to use the Nmap::Scanner module.
http://search.cpan.org/~maxschube/Nmap-Scanner-1.0/lib/Nmap/Scanner.pm


thanks for the reply :]

i might have jumped the gun with saying system and nmap.

i agree that it does depend on the version but really nmap was just an example since i know it takes simple input and gives you something in return.

i would like to do with other things such as custom scripts/apps i write.

to make it more generic, let me start over:

instead of using system to execute a command, what can i use to execute a command and then communicate with it via the keyboard while it's running.

i'm also having trouble googling the answer because obviously i also have trouble describing what i want to do even though it seems so simple in my head. lol

maybe 'open' with a while loop and 'stdin'?

if you or anyone else happens to know i've subscribed to this thread. if not i'll keep playing with it and if i come up with something and post back.


FishMonger
Veteran / Moderator

Oct 31, 2012, 1:48 PM

Post #4 of 4 (1016 views)
Re: [testbot] quick question regarding sending keys to system command [In reply to] Can't Post

IPC::Open2 - open a process for both reading and writing using open2()
http://search.cpan.org/~dom/perl-5.14.3/ext/IPC-Open2/lib/IPC/Open2.pm

IPC::Open3 - open a process for reading, writing, and error handling using open3()
http://search.cpan.org/~dom/perl-5.14.3/ext/IPC-Open3/lib/IPC/Open3.pm

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives