Path: ...!news.misty.com!weretis.net!feeder9.news.weretis.net!news.quux.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!eternal-september.org!.POSTED!not-for-mail From: Kaz Kylheku <643-408-1753@kylheku.com> Newsgroups: comp.unix.shell Subject: Re: Initiate command in another shell session? Date: Thu, 13 Mar 2025 16:49:48 -0000 (UTC) Organization: A noiseless patient Spider Lines: 45 Message-ID: <20250313093734.372@kylheku.com> References: Injection-Date: Thu, 13 Mar 2025 17:49:48 +0100 (CET) Injection-Info: dont-email.me; posting-host="af2561aed5a48a7d058827d49eed31d1"; logging-data="3674570"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1806Be/xjsjIiDWwZLM+YOjU91v8W1l0P8=" User-Agent: slrn/pre1.0.4-9 (Linux) Cancel-Lock: sha1:u2d+yg0gPBq9NpDQ66RJqHE+joA= Bytes: 2829 On 2025-03-13, Janis Papanagnou wrote: > The question occurred to me whether it would be possible to remotely > execute a command as if started from another shell session *in* that > shell session. The target shell session has to run some service loop listening for these requests, on a pipe or something. On top of that you can build remote procedure calls. Running any command specified by the caller is equivalent to having "eval" available as a remote procedure call. Or something lesser: running any simple command (command name with arguments). When the function unpacks the arguments, it can subject them to some validation, checking for allowed commands or command/argument combinations. About the service loop, we don't have threads in the popular shells like Bash. If it's all one the same machine, you could set a trap for a signal in the target shell. Then when the caller deposits a message in the message box (however that is implemented) it kills that shell with the signal. The trap handler will then dispatch the RPC. If the target shell is interactive, you might want it so that the commands are not immediately dispatched while that shell is executing code, only when it's ide. (And by the way, when the shell is suspended waiting for an external command, like an editor to exit, it won't be able to take RPCs). The trap handler can check a global flag indicating whether the shell is idle (OK to dispatch command now) or busy (queue the command, to be run when it goes out of the busy state). As you can guess, my thinking here is influenced by having worked on the Basta extension, which updates the status line in response to timer signals. -- TXR Programming Language: http://nongnu.org/txr Cygnal: Cygwin Native Application Library: http://kylheku.com/cygnal Mastodon: @Kazinator@mstdn.ca