Hello everybody! I have a quick question. I'm sending an exec command with:

          Channel channel=session.openChannel("exec");
           ((ChannelExec)channel).setCommand(commandToRun);
           channel.setInputStream(null);
           channel.setOutputStream(null);
           ((ChannelExec)channel).setErrStream(null);
            channel.connect();

When I close my java GUI, the process I run on Unix (with the unix nohup 
command so it keeps running even if the session closes) dies after a few 
seconds.

Does anyone have any idea why? I create the channel with a new thread, passing 
the session object to the Class constructor. Anybody see anything wrong with 
what I'm doing here? Thank you for your help! Here is the full code:

public class RunThreadedCommand extends Thread {
  
    private boolean started,stopThread = false;
    private String commandToRun;
    private Session session;

    public RunThreadedCommand(String commandToRunx, Session sessionx) {
        commandToRun=commandToRunx;
        session=sessionx;
    }

    @Override
    public void start() {

      if(!started) {
        started = true;
        super.start();
      }

    }

    public void stopThread() {
        stopThread=true;
    }

    @Override
    public void run() {

      runCommand(commandToRun);
      while (!stopThread) {
        try {
          sleep(5000);
        } catch(InterruptedException e) {
          System.err.println("Interrupted" + e);
        }
      }       
    }

    public void runCommand(String commandstr){
        

        try {
           Channel channel=session.openChannel("exec");
           ((ChannelExec)channel).setCommand(commandToRun);
           channel.setInputStream(null);
           channel.setOutputStream(null);
           ((ChannelExec)channel).setErrStream(null);

            channel.connect();
        } catch (Exception e) {
            System.out.println(e);
        }


    }
}//end RunThreadedCommand class

_________________________________________________________________

-------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://sourceforge.net/services/buy/index.php
_______________________________________________
JSch-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/jsch-users

Reply via email to