0

I need to run g++ compiled program and get exit status. My code in nodejs:

import pty from "node-pty";
...

ptyProcess.write("exec /var/www/a.out\r\n'");

What I found:

$! is the PID of the last process sent to the background

$? is the exit code of the last process

It means. I can do in terminal: /var/www/a.out && echo $? - result, running program and in the end 0 (Success exit code). Hovewer, exec don't allow to run any commands after it, as once a.out is done, exec closes.

Problem is, I am making web c++ compiler & debugger, and I want to give exec output to user (web page) to debug his written code... Once exec is done, he don't get root to whole terminal. If I use without exec, then after program is done, he can get root@server:~# .. If something is unclear, please ask in comments and I will try to explain better.

UPDATE. OK seems I can use /var/www/a.out && echo $? && exit, it is fine when program ends successfully, however if I try to press CTRL+C or CTRL+Z, I can break command and get root. With exec when you press these combinations, you don't get root.

UPDATE 2. Okay, so I ended with this:

trap '' 2 3 20 && /var/www/a.out && echo $? && exit\r\n

trap disables CTRL combinations:

SIGINT=CTRL-C

SIGQUIT=CTRL-\

SIGTSTP=CTRL-Z

1
  • programming question should be asked on Stack Overflow because it is associated with programing
    – djdomi
    Apr 16 at 18:07

0

You must log in to answer this question.

Browse other questions tagged .