.

scripting question

<<

venom77

User avatar

Hero Member
Hero Member

Posts: 1905

Joined: Mon Dec 11, 2006 3:23 pm

Post Sun Oct 02, 2011 8:53 am

scripting question

I want to run an app (call it 'app') and I want to automatically supply it with some responses that it requires, in order (say 'yes', 'no', 'maybe').

What is the proper way to do this? Google hasn't helped much or I haven't found the right way to phrase this in my searching.

The closest I have found was to do this:

yes | ./app

That's only for a single response (I need multiple) but my app just crashes at the first prompt anyway:

[yes|no]: yes: command not found

As if it's trying to run another script/app called 'yes' or something. I've also tried placing yes in single/double quotes with the same outcome.

Any suggestions would be great! Thanks!
<<

hayabusa

User avatar

Hero Member
Hero Member

Posts: 1662

Joined: Mon Jan 29, 2007 2:59 pm

Post Sun Oct 02, 2011 9:18 am

Re: scripting question

How about something like:

http://lists.gnu.org/archive/html/bug-b ... 00104.html

I haven't had to do auto responses to apps in a while, so you had me thinking...
~ hayabusa ~ 

"All men can see these tactics whereby I conquer, but what none can see is the strategy out of which victory is evolved." - Sun Tzu, 'The Art of War'


OSCE, OSCP , GPEN, C|EH
<<

MaXe

User avatar

Hero Member
Hero Member

Posts: 671

Joined: Tue Aug 17, 2010 9:49 am

Post Sun Oct 02, 2011 11:28 am

Re: scripting question

You could use "aliases" inside the bash shell, in case you want the "yes" command to do something with the word "yes", which is interpreted as a program which is not installed.

The way you want to supply an arg for 'app', is a bit non-standard.

Often, you could most likely supply arguments like this:
./app | perl -e 'print "Yes"'

I'm not sure if you can use this, but "xargs" may be what you are also looking for. Example command line:
find . | grep '.txt' | xargs cat

That would basically list all files (from the current directory recursively), show only those with .txt, and then "cat" each and one of them.

Basically, if you want to control this 'app', you need to either:
A) Run it and then redirect output, or pipe input into it like ./app | echo yes (or use python or perl for that sake), OR
B) Use a program or script infront of the APP, which supplies these "responses" to the program. E.g.:
./yes.py | app

yes.py contains the following code then:
print "yes"

You can of course, write a script that returns the response you give it, here's how you can do it in PHP:
#!/usr/bin/env php
<?php echo $argv[1]; ?>

Then chmod +x response php

./response.php yes | app

Basically just another way :)
I'm an InterN0T'er
<<

venom77

User avatar

Hero Member
Hero Member

Posts: 1905

Joined: Mon Dec 11, 2006 3:23 pm

Post Sun Oct 02, 2011 8:07 pm

Re: scripting question

Thanks for the ideas! I will try these out as soon as I get a chance and report back.

Return to Other

Who is online

Users browsing this forum: No registered users and 1 guest

cron
.
Powered by phpBB® Forum Software © phpBB Group.
Designed by ST Software