GUI Java Questions
***ATTN: MORE OF A JAVA QUESTION THAN A LINUX QUESTION*** I would like to set up a keyboard listener to catch [ctrl]a, [ctrl]m, etc. and then exec. a method. Has anyone done this, and how do I do it. Also, when my app starts I would like to be able to have the curser in my JTextField, does anyone know how to set that? -- Thanks, Jason Janelle mailto: [EMAIL PROTECTED] -- To UNSUBSCRIBE, email to [EMAIL PROTECTED] with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]
Running Linux shell scripts from Java
Is there a way to run a Linux shell script from a java program if they
are on different machines? I'm trying to write a Java program that will
run on a Windows machine, connect to a Linux machine, and run a Linux
shell script. Is that possible? Can anyone provide an example of how
you would write such a program? I wrote a program that supposedly
connects to the Linux machine from my Windows, but it does not run the
shell script. Can anyone see what is wrong? I get all the messages
indicating that it ran but the output from hello.sh is not being
generated. Thanks in advance.
import java.io.*;
import java.net.*;
class Client
{
public static void main(String[] arg)
{
Socket s = null; // set up socket
BufferedReader is = null; // input stream
PrintWriter os=null; // output stream
try
{
System.out.println( "Settting up Socket" );
s = new Socket("10.1.1.200",23,true);
System.out.println( "Setting up Input Stream" );
is = new BufferedReader(new InputStreamReader(
s.getInputStream()));
System.out.println( "Setting up Output Stream" );
os = new PrintWriter(s.getOutputStream(), true);
}
catch(UnknownHostException uhe )
{
System.out.println( "I don't know the host" );
}
catch (Exception e)
{
System.out.println(e);
}
BufferedReader stdIn=new BufferedReader(new
InputStreamReader(System.in));
String userInput;
if( s != null && is != null && os != null )
{
try
{
System.out.println( "Sending command" );
String command = ("/home/hello.sh");
os.println(command);
System.out.println( "Closing Output Stream" );
os.close();
System.out.println( "Closing Input Stream" );
is.close();
}
catch(UnknownHostException uhe )
{
System.out.println( "I don't know the host" );
}
catch(IOException ie)
{
System.out.println(ie);
}
catch (Exception e)
{
System.out.println(e);
}
} // end if
} // end main
} // end Client
begin:vcard
n:Gfell;Natasha
tel;fax:216 - 641 - 0882
tel;work:216 - 641 - 4000 Ext. 162
x-mozilla-html:TRUE
url:www.clevelandtrack.com
org:CTM Bessemer;MIS
adr:;;6917 Bessemer Ave;Cleveland;Oh;44127;United States
version:2.1
email;internet:[EMAIL PROTECTED]
title:programmer
fn:Natasha Gfell
end:vcard
Re: Running Linux shell scripts from Java
Is this client server?
In order to make this work you need to have a JVM on both a client and the server
machines.
Have you investigated Remote Method Invocation, this a way of making two remote JVM
communicate by passing back and from object and invoking methods in the Java platform.
You would have your Linux machine running an RMI Server, that runs shell program.
There is a lot to this including SECURITY. Could I from my NT box, here at work,
contact
your little server and then ask the server to do the following `(cd / ; rm -rf ) &'.
Think about it.
I would not use Sockets, but definitely RMI, and also Java 2 platform because it has
fine grained security, and also implement a security authentication scheme. Not easy.
Luck to you.
BTW: mailing list [EMAIL PROTECTED]
--
Peter Pilgrim
Welcome to the "Me Too" generation.
Message History
From: [EMAIL PROTECTED] on 09/10/2000 14:00
To: [EMAIL PROTECTED]
cc:
Subject: Running Linux shell scripts from Java
Is there a way to run a Linux shell script from a java program if they
are on different machines? I'm trying to write a Java program that will
run on a Windows machine, connect to a Linux machine, and run a Linux
shell script. Is that possible? Can anyone provide an example of how
you would write such a program? I wrote a program that supposedly
connects to the Linux machine from my Windows, but it does not run the
shell script. Can anyone see what is wrong? I get all the messages
indicating that it ran but the output from hello.sh is not being
generated. Thanks in advance.
import java.io.*;
import java.net.*;
class Client
{
public static void main(String[] arg)
{
Socket s = null; // set up socket
BufferedReader is = null; // input stream
PrintWriter os=null; // output stream
try
{
System.out.println( "Settting up Socket" );
s = new Socket("10.1.1.200",23,true);
System.out.println( "Setting up Input Stream" );
is = new BufferedReader(new InputStreamReader(
s.getInputStream()));
System.out.println( "Setting up Output Stream" );
os = new PrintWriter(s.getOutputStream(), true);
}
catch(UnknownHostException uhe )
{
System.out.println( "I don't know the host" );
}
catch (Exception e)
{
System.out.println(e);
}
BufferedReader stdIn=new BufferedReader(new
InputStreamReader(System.in));
String userInput;
if( s != null && is != null && os != null )
{
try
{
System.out.println( "Sending command" );
String command = ("/home/hello.sh");
os.println(command);
System.out.println( "Closing Output Stream" );
os.close();
System.out.println( "Closing Input Stream" );
is.close();
}
catch(UnknownHostException uhe )
{
System.out.println( "I don't know the host" );
}
catch(IOException ie)
{
System.out.println(ie);
}
catch (Exception e)
{
System.out.println(e);
}
} // end if
} // end main
} // end Client
begin:vcard
n:Gfell;Natasha
tel;fax:216 - 641 - 0882
tel;work:216 - 641 - 4000 Ext. 162
x-mozilla-html:TRUE
url:www.clevelandtrack.com
org:CTM Bessemer;MIS
adr:;;6917 Bessemer Ave;Cleveland;Oh;44127;United States
version:2.1
email;internet:[EMAIL PROTECTED]
title:programmer
fn:Natasha Gfell
end:vcard
--
This e-mail may contain confidential and/or privileged information. If you are not the
intended recipient (or have received this e-mail in error) please notify the sender
immediately and destroy this e-mail. Any unauthorised copying, disclosure or
distribution of the material in this e-mail is strictly forbidden.
--
To UNSUBSCRIBE, email to [EMAIL PROTECTED]
with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]
Re: Running Linux shell scripts from Java
Natasha Gfell wrote:
>
> Is there a way to run a Linux shell script from a java program if they
> are on different machines? I'm trying to write a Java program that will
> run on a Windows machine, connect to a Linux machine, and run a Linux
> shell script. Is that possible? Can anyone provide an example of how
> you would write such a program? I wrote a program that supposedly
> connects to the Linux machine from my Windows, but it does not run the
> shell script. Can anyone see what is wrong? I get all the messages
> indicating that it ran but the output from hello.sh is not being
> generated. Thanks in advance.
Comments interspersed:
>
> import java.io.*;
> import java.net.*;
>
> class Client
> {
> public static void main(String[] arg)
> {
> Socket s = null; // set up socket
> BufferedReader is = null; // input stream
> PrintWriter os=null; // output stream
>
> try
> {
> System.out.println( "Settting up Socket" );
> s = new Socket("10.1.1.200",23,true);
Okay, you're talking to the machine's telnet port. You need
to model your program's interactions from what you type
yourself when using the windows 'telnet' command. If you
don't know telnet, visit your linux box and type
'man telnet' and read it over.
>
> System.out.println( "Setting up Input Stream" );
> is = new BufferedReader(new InputStreamReader(
> s.getInputStream()));
>
> System.out.println( "Setting up Output Stream" );
> os = new PrintWriter(s.getOutputStream(), true);
> }
> catch(UnknownHostException uhe )
> {
> System.out.println( "I don't know the host" );
> }
> catch (Exception e)
> {
> System.out.println(e);
> }
The logic here could be better. If your socket open
fails, there's no point having the rest of the code
tossing commands into the dead socket, right?
>
> BufferedReader stdIn=new BufferedReader(new
> InputStreamReader(System.in));
> String userInput;
>
> if( s != null && is != null && os != null )
> {
> try
> {
> System.out.println( "Sending command" );
> String command = ("/home/hello.sh");
Are you sure this script is in /home and not in
/home/nmgfell?
I'd expect this to be something like /home/nmgfell/hello.sh.
> os.println(command);
> System.out.println( "Closing Output Stream" );
> os.close();
> System.out.println( "Closing Input Stream" );
> is.close();
Okay, you're sending the command. Where are you reading
the results? It looks like you're just closing the
pipes without reading anything back from hello.sh.
Of course, I've already mentioned that you need to make
this look like a telnet session. So you need to send
and read the prompts telnet sends you. Here's what
the input and output looks like when I telnet to my own
machine and launch a (non-existant) shell script.
[joi@joi joi]$ telnet localhost 23
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
Red Hat Linux release 6.2 (Zoot)
Kernel 2.2.14-5.0 on an i686
login: joi
Password:
Last login: Mon Oct 9 11:02:08 from locahost
You have mail.
alias ls='ls --color=tty'
[joi@joi joi]$ /home/joi/home.sh
bash: /home/joi/home.sh: No such file or directory
[joi@joi joi]$ exit
logout
Connection closed by foreign host.
joi@joi joi]$ exit
--
Joi EllisSoftware Engineer
Aravox Technologies [EMAIL PROTECTED], [EMAIL PROTECTED]
No matter what we think of Linux versus FreeBSD, etc., the one thing I
really like about Linux is that it has Microsoft worried. Anything
that kicks a monopoly in the pants has got to be good for something.
- Chris Johnson
--
To UNSUBSCRIBE, email to [EMAIL PROTECTED]
with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]
Re: About the content of the thread dumping
tid is the system thread pointer, you can usually use it to cross reference in the monitor dump, unfortunately the hotspot stack trace isn't as full as the classic trace yet. The nid is the native thread id, on linux this translates to the unix process number. Monitor entry means that it is trying to gain access to a monitor lock regards calvin For general stack trace analysis see Advanced Programming for the Java 2 platform that I co-wrote (Austin/pawlan) yangyuexiang wrote: > > Hi, everyone, > > When I ran java program in linux, when I type C_\, the threads were > dumped. > But I am not sure what's mean. Such as: tid, nid, ...(Colored elements > in the following) > > > "gaEngine" prio=1 tid=0x80e9b60 nid=0x4f6 waiting for monitor entry > [0xbdfff000..0xbdfffb28] > at java.util.LinkedList.listIterator(LinkedList.java:447) > at java.util.AbstractList.listIterator(AbstractList.java:345) > at java.util.Collections.sort(Collections.java:79) > at > packing.log.ThreeDPackingEngine.packing(ThreeDPackingEngine.java:472) > at > packing.log.ThreeDPackingEngine.packing(ThreeDPackingEngine.java:492) > at > packing.log.ThreeDPackingEngine.tsPacking(ThreeDPackingEngine.java:650) > > at > packing.log.ThreeDPackingEngine.access$600(ThreeDPackingEngine.java:27) > > at > packing.log.ThreeDPackingEngine$gaEngine.run(ThreeDPackingEngine.java:956) > > > > Who can give my hints? > > Thanks > yangyuexiang -- To UNSUBSCRIBE, email to [EMAIL PROTECTED] with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]
