Calling of external scripts

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Calling of external scripts

Dan Beck
Hello,

I am newbie in using of BeanShell. I was trying to dig through docs and Google as well, but gave up. :-/

I am looking for simple example of code doing the following stuff (if it's even possible):

... some BeanShell commands ...
call external script (bash, python, perl, ...)
take the output of the script above and use it
... some BeanShell commands ...

The external script would most probably return one line of text (if more, I can workaround it with multiple calls of external script).

Thanks for any code excerpts, directions to them or any other help.

Regards

DB

-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >>  http://get.splunk.com/
_______________________________________________
Beanshell-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/beanshell-users
Reply | Threaded
Open this post in threaded view
|

Re: Calling of external scripts

Stewart Cambridge
Haven't tried it, but seeing as beanshell is scripting for the java
language, then why not try doing what you would do in java?

Process p = Runtime.getRuntime().exec("cmd");
BufferedReader stdInput = new BufferedReader(new
InputStreamReader(p.getInputStream()));
BufferedReader stdError = new BufferedReader(new
InputStreamReader(p.getErrorStream()));

On 03/08/07, Dan Beck <[hidden email]> wrote:

> Hello,
>
> I am newbie in using of BeanShell. I was trying to dig through docs and Google as well, but gave up. :-/
>
> I am looking for simple example of code doing the following stuff (if it's even possible):
>
> ... some BeanShell commands ...
> call external script (bash, python, perl, ...)
> take the output of the script above and use it
> ... some BeanShell commands ...
>
> The external script would most probably return one line of text (if more, I can workaround it with multiple calls of external script).
>
> Thanks for any code excerpts, directions to them or any other help.
>
> Regards
>
> DB
>
> -------------------------------------------------------------------------
> This SF.net email is sponsored by: Splunk Inc.
> Still grepping through log files to find problems?  Stop.
> Now Search log events and configuration files using AJAX and a browser.
> Download your FREE copy of Splunk now >>  http://get.splunk.com/
> _______________________________________________
> Beanshell-users mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/beanshell-users
>

-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >>  http://get.splunk.com/
_______________________________________________
Beanshell-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/beanshell-users
Reply | Threaded
Open this post in threaded view
|

Re: Calling of external scripts

Alexey Zinger
In reply to this post by Dan Beck
How about this (I wasn't paying attention to exception handling, so you'd have
to add that as necessary):

Interpreter bsh = ...;
String scriptFileName = ...;

ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
bsh.setOut(new PrintStream(outputStream));
bsh.setErr(bsh.getOut());

bsh.source(scriptFileName);

String output = outputStream.toString(); // voila!

--- Dan Beck <[hidden email]> wrote:

> Hello,
>
> I am newbie in using of BeanShell. I was trying to dig through docs and
> Google as well, but gave up. :-/
>
> I am looking for simple example of code doing the following stuff (if it's
> even possible):
>
> ... some BeanShell commands ...
> call external script (bash, python, perl, ...)
> take the output of the script above and use it
> ... some BeanShell commands ...
>
> The external script would most probably return one line of text (if more, I
> can workaround it with multiple calls of external script).
>
> Thanks for any code excerpts, directions to them or any other help.
>
> Regards
>
> DB
>
> -------------------------------------------------------------------------
> This SF.net email is sponsored by: Splunk Inc.
> Still grepping through log files to find problems?  Stop.
> Now Search log events and configuration files using AJAX and a browser.
> Download your FREE copy of Splunk now >>  http://get.splunk.com/
> _______________________________________________
> Beanshell-users mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/beanshell-users
>


Alexey
2001 Honda CBR600F4i (CCS)
1992 Kawasaki EX500
http://azinger.blogspot.com
http://bsheet.sourceforge.net
http://wcollage.sourceforge.net



      ____________________________________________________________________________________
Park yourself in front of a world of choices in alternative vehicles. Visit the Yahoo! Auto Green Center.
http://autos.yahoo.com/green_center/ 

-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >>  http://get.splunk.com/
_______________________________________________
Beanshell-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/beanshell-users