[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[no subject]
- <!--x-content-type: text/plain -->
- <!--x-date: Sun May 23 15:45:10 2004 -->
- <!--x-from-r13: psbjyre ng bhgcbfgfragvary.pbz (Quevfgbcure Tbjyre) -->
- <!--x-message-id: [email protected] -->
- <!--x-reference: [email protected] -->
- <!--x-reference: [email protected] --> "http://www.w3.org/TR/html4/loose.dtd">
- <!--x-subject: [ale] Crazy Perl + Java question -->
- <li><em>date</em>: Sun May 23 15:45:10 2004</li>
- <li><em>from</em>: cfowler at outpostsentinel.com (Christopher Fowler)</li>
- <li><em>in-reply-to</em>: <<a href="msg00915.html">[email protected]</a>></li>
- <li><em>references</em>: <<a href="msg00914.html">[email protected]</a>> <<a href="msg00915.html">[email protected]</a>></li>
- <li><em>subject</em>: [ale] Crazy Perl + Java question</li>
--- Cut Here ----
[tomcat at SAM-devel SAM]$ cat jcd.java
public class jcd {
public static void main(String args[]) {
JCD j = new JCD("192.168.2.231", "ensign", "password");
try {
System.out.print(j.get_buffer("Solaris"));
} catch (Exception exp) {
System.err.println(exp.getMessage());
}
}
}
--- Cut Here ---
[tomcat at SAM-devel SAM]$ cat jcd.java
public class jcd {
public static void main(String args[]) {
JCD j = new JCD("192.168.2.231", "ensign", "password");
try {
System.out.print(j.get_buffer("Solaris"));
} catch (Exception exp) {
System.err.println(exp.getMessage());
}
}
}
[tomcat at SAM-devel SAM]$ cat JCD.java
import java.io.*;
public class JCD {
private String _HOST;
private String _USER;
private String _PASS;
private static final String _CMD = "/opt/SAM/jcd.pl";
public JCD(String v1, String v2, String v3) {
_HOST = v1;
_USER = v2;
_PASS = v3;
}
public String get_buffer(String console)
throws Exception {
StringBuffer BUFFER = new StringBuffer("");
try {
Process p = null;
String r[] = {
_CMD,
"-u" + _USER,
"-s" + _HOST,
"-p" + _PASS,
"-Se",
"get_buffer(" + console + ")"
};
p = Runtime.getRuntime().exec(r);
BufferedInputStream buffer =
new
BufferedInputStream(p.getInputStream());
BufferedReader br = new BufferedReader(new
InputStreamReader(buffer));
String s = null;
try {
while ((s = br.readLine()) != null) {
BUFFER.append(s);
BUFFER.append("\n");
}
br.close();
p.waitFor();
if(p.exitValue() != 0) {
/**
* Is there anyway I can parse STDERR?
*/
throw new Exception("Error: execution
error when trying to get console data.");
}
} catch (Exception e) { /** Read errors are
normal */}
} catch (Exception e) {
throw new Exception("ERROR!:"+ e.getMessage());
}
return BUFFER.toString();
}
}
/** vi: set ts=2 sw=2: */
-- Cut Here ---
The speed is not bad either.
On Sun, 2004-05-23 at 15:27, Christopher Fowler wrote:
> Here is what I came up with.
>
> I created an interface that used Getopt to allow the user to pass all
> arguments needed to create a JD object. I then added a -e (exec)
> options that allowed the user to pass the method and arguments for that
> class that needed to be executed.
>
> In this example I called up my remote JCD server and asked it for the
> console buffer contents of my Soalris 9 machine.
>
> ./jcd.pl -u ensign -p password -s 192.168.2.231 -S -e
> "get_buffer('Solaris')"
>
> What I got back was:
>
>
> sol9 console login: root
> Password:
> May 21 14:28:38 sol9 login: ROOT LOGIN /dev/console
> Last login: Thu May 20 23:53:11 on console
> Sun Microsystems Inc. SunOS 5.9 Generic May 2002
> # passwd
> passwd: Changing password for root
> New Password:
> Re-enter new Password:
> passwd(SYSTEM): They don't match.
>
> Please try again
> New Password:
> Re-enter new Password:
> passwd: password successfully changed for root
> # ^D
> sol9 console login:
> sol9 console login:
> sol9 console login:
>
>
> The beauty of this is that the '-S' switched used SSL as the connection
> and I did not have to waste my times with the problems of java not
> allowing a connection to a remote site that did not have a signed cert.
>
> Unless there is a way to call perl code directly from Java I think this
> would be the best way. I guess I could write a JNI interface that can
> return Java objects but that might be a royal PITA.
>
>
>
> On Sun, 2004-05-23 at 15:00, Christopher Fowler wrote:
> > I was on my way to Home Depot to by some shelving for my ever growing
> > collection of technical manuals. I purchased about 10 books in the last
> > 2 weeks. I'm running out of space in my home office for all this
> > storage. Back on subject.... I was thinking about some classes that I
> > need to write in Java to use in our J2EE app that I've written in Perl.
> > I would like to know if there is any way to reuse that perl code so I do
> > not have to write more in Java?
> >
> > All of the data that is returned are Strings. I could create a simple
> > command line interface to the perl class and have Java execute it in a
> > process thread. Is that a crazy idea? Is there a better more efficient
> > way?
> >
> > Chris
> >
> > _______________________________________________
> > Ale mailing list
> > Ale at ale.org
> > <a rel="nofollow" href="http://www.ale.org/mailman/listinfo/ale">http://www.ale.org/mailman/listinfo/ale</a>
>
> _______________________________________________
> Ale mailing list
> Ale at ale.org
> <a rel="nofollow" href="http://www.ale.org/mailman/listinfo/ale">http://www.ale.org/mailman/listinfo/ale</a>
</pre>
<!--X-Body-of-Message-End-->
<!--X-MsgBody-End-->
<!--X-Follow-Ups-->
<hr>
<!--X-Follow-Ups-End-->
<!--X-References-->
<ul><li><strong>References</strong>:
<ul>
<li><strong><a name="00914" href="msg00914.html">[ale] Crazy Perl + Java question</a></strong>
<ul><li><em>From:</em> cfowler at outpostsentinel.com (Christopher Fowler)</li></ul></li>
<li><strong><a name="00915" href="msg00915.html">[ale] Crazy Perl + Java question</a></strong>
<ul><li><em>From:</em> cfowler at outpostsentinel.com (Christopher Fowler)</li></ul></li>
</ul></li></ul>
<!--X-References-End-->
<!--X-BotPNI-->
<ul>
<li>Prev by Date:
<strong><a href="msg00915.html">[ale] Crazy Perl + Java question</a></strong>
</li>
<li>Next by Date:
<strong><a href="msg00917.html">[ale] knoppix myconfig=scan home=scan</a></strong>
</li>
<li>Previous by thread:
<strong><a href="msg00915.html">[ale] Crazy Perl + Java question</a></strong>
</li>
<li>Next by thread:
<strong><a href="msg00917.html">[ale] knoppix myconfig=scan home=scan</a></strong>
</li>
<li>Index(es):
<ul>
<li><a href="maillist.html#00916"><strong>Date</strong></a></li>
<li><a href="threads.html#00916"><strong>Thread</strong></a></li>
</ul>
</li>
</ul>
<!--X-BotPNI-End-->
<!--X-User-Footer-->
<!--X-User-Footer-End-->
</body>
</html>