2

I'm trying to create a very simple 'Run Box' as an item from the TWM window manager menu as TWM does not provide such a function.

From my menu I have;

"Run" f.exec "xterm -fg black -bg white -geometry 25x1 -T Run -e 'read input && exec $input' &"

Whilst this creates a nice little run dialogue which takes in user input, it remains running whilst the child program is running - when it should quit out of the way immediately the child process is launched.

This seemed like a simple idea initially but is now looking way harder than my scripting fu provides for. Any tips?

0
1

I think the & in the end of the command line is not what you intended according to the description of your question. In this case, you're putting xterm into the background and keeps the script running, but there's nothing to run after xterm. You might want to put the & before the finishing quote, inside the executing comma. I can't guarantee it will work, however, as I'm unsure about the xterm behavior and parameters and about how TWM works. If it does not work, I'll show an example of how to do it in a standard shell, which might be reproducible to the context you're using it through a separate script.

As an example of how to test and implement that, I have created two scripts in my /tmp/ directory. The first one, runbg.sh, contains the expected functionality:

#!/bin/sh

read cmdline
$cmdline &

The second script, /tmp/infiniteloop.sh, is a way to test if it's working as expected, it's an infinite loop with a sleeping timer appending every iteration the current date to the file /tmp/infiniteloop.tmp.

#!/bin/sh

while true; do
  date >> /tmp/infiniteloop.tmp
  sleep 30
done

If you then run /tmp/runbg.sh, and you type the command /tmp/infiniteloop.sh, it's going to leave you back in the shell. You can check the infiniteloop.sh script is still running through a tail -f /tmp/infiniteloop.tmp, which will show you a new line with the current date every 30 seconds if you did everything right.

So, in your case, my suggestion is to write a separate shell script for reading the command and running it in the background, and then call the script in the TWM menu config file.

2
  • 1
    You seem to have forgotten to finish typing your answer.  P.S. You need only three backticks for a code block. – Scott Jul 13 '20 at 9:01
  • Thanks, @Scott, I fixed it! Also, thanks for the hint about the code block!! – Bruno Jul 15 '20 at 0:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.