Score:0

Linux / NodeJS get exitcode of process runned by "exec"

pm flag

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

djdomi avatar
za flag
programming question should be asked on [so] because it is associated with programing
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.