Remote process stops as soon as my Java app exits

  Kiến thức lập trình

I’m running a remote process through my Java app which I want to keep running throughout the lifespan of my app as well as after it (my app) exits unless some remote user terminates it or a local user terminates it using an icon inside my app. Right now, it terminates as soon as my Java app exits. I think this happens because the object “shellChannel” gets destroyed upon app exit. Following is the code:

public static void runProcess() {
    MainPC pc = (MainPC)MainWindow.getInstance().selectedNode.getUserObject();
    
    try {
        if (connectedShellChannel(pc)) {
            PrintStream shellStream = new PrintStream(pc.shellChannel.getOutputStream(), true);
            // where shellChannel is com.jcraft.jsch.Channel object created elsewhere
            shellStream.println("./st.cmd");

            shellStream.flush();
            shellStream.close();

            Prompt.ShowInfo("Specified process is now running successfully n on selected PC (IP: " + pc.IP + ")", "Message from Remote PC", Global.SuccessIcon);
        }
    } catch (IOException e) {
        e.printStackTrace();
        Prompt.ShowError("A secure communication channel could not be established n with the Remote PC.nnSpecified process could not be run.", "Secure Communication not established");
    }
}

Any suggestions??

Theme wordpress giá rẻ Theme wordpress giá rẻ Thiết kế website

LEAVE A COMMENT