Hi,

 

I am having a problem understanding some of the concepts I guess.

Here is what I want to do:

1. I want to run a program through ssh (on a remote UNIX system)

2. get the process ID

3. close the session

4. be able to check if the program is still running by checking if the
process id is still listed with the ps command.

 

Here is what I am doing and that is not working correctly:

 

JSch jsch = new JSch();

java.util.Properties config = new java.util.Properties();

// for developing purposes I disable strick thostkey checking.

config.put("StrictHostKeyChecking", "no");

Session session = jsch.getSession(myuser, myhost, 22);

session.setPassword(mypwd);

session.setConfig(config);

session.connect();

 

//maybe I need to use nohup???

String command = cmd + " &>" + outfp + " &";

Channel channel = session.openChannel("shell");

// I am using ByteArrayInputStream because that's the only so far that gave
me a inputStream

// I don't know how to understand the inputStream concept and what is the
difference between inputstream and outputstream

// i.e. I can only write to the output stream, but I am expecting to
actually read from it... ?????

InputStream ioIn = new ByteArrayInputStream(

                        command.getBytes());

// If I understand correctly this tells the channel to keep all the "output"
from the command line and I can then read it using the input stream 

channel.setInputStream(null);

// this is the input stream i can use to read the data coming from the
command line????

InputStream in = channel.getInputStream();

// this will execute the command ???

channel.connect();

// this then reads the output

byte[] tmp = new byte[1024];

while (true) {

            System.err.println("reading data-1");

            while (in.available() > 0) {

                        System.err.println("reading data-2");

                        int i = in.read(tmp, 0, 1024);

                        if (i < 0)

                                    break;

                        String rmtout = new String(tmp, 0, i);

                        String [] fps_tmp = rmtout.split("\n");

                        for(int x=0; x<fps_tmp.length; x++){

                                    if(fps_tmp2 == null)        

                                                fps_tmp2 = new
ArrayList<String>();

                                    fps_tmp2.add(fps_tmp[x]);

                        }

                        System.err.println(rmtout);

            }

            if (channel.isClosed()) {

                        System.err.println("exit-status: "

                                                + channel.getExitStatus());

                        break;

            }

            try {

                        Thread.sleep(1000);

            } catch (Exception ee) {

            }

}

channel.disconnect();

session.disconnect();

 

 

OK, that process was working for the "exec" connection, but now it is not
working. I don't get the command to run. Or do I???

When printing out what I am reading I see:

BEGIN OF OUTPUT=>

Last login: Thu Sep 24 14:31:07 2009 from XXX.YYYY.ZZZZ

 

/xxxxxx/solexa2/solexa_travail/PF2/programs/mylocal/bin/novoalign -r All -a
ATCTCGTATGCCGTCTTCTGCTTG -f
/xxxxxx/solexa2/solexa_travail/PF2/090616_HWI-EAS285/Gerald/L1_SC0/Error.htm
-d /xxxxxx/solexa2/solexa_travail/PF2/novo_genomes/dm3
&>/xxxxxx/solexa2/solexa_travail/PF2/090616_HWI-EAS285/Gerald/L1_SC0/novo/Er
ror.htm.novo &-bash-3.00$
/xxxxxx/solexa2/solexa_travail/PF2/programs/mylocal/bin/novoalign 

 

-r All -a ATCTCGTATGCCGTCTTCTGCTTG -f
/xxxxxx/solexa2/solexa_travail/PF2/09061

 

6_HWI-EAS285/Gerald/L1_SC0/Error.htm -d
/xxxxxx/solexa2/solexa_travail/PF2/nov

 

o_genomes/dm3
&>/xxxxxx/solexa2/solexa_travail/PF2/090616_HWI-EAS285/Gerald/L1

 

_SC0/novo/Error.htm.novo &

 

<=END OF OUTPUT

 

Why is everything repeated? 

How come these weired line-breaks are introduced?

What is going wrong?

 

I am totally confused and really need some help!!!!

 

Please help,

 

Bernd

 

------------------------------------------------------------------------------
Come build with us! The BlackBerry&reg; Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay 
ahead of the curve. Join us from November 9&#45;12, 2009. Register now&#33;
http://p.sf.net/sfu/devconf
_______________________________________________
JSch-users mailing list
JSch-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jsch-users

Reply via email to