I am grabbing the keyboard using ioctl(fd,EVIOCGRAB,(void*)1), but the terminal keeps sending the shell newlines from executing the program. The same problem as in this question.
Is there a way to solve this without calling sleep() before ioctl?
The solution I came up with was to read from the keyboard device once before calling ioctl(fd,EVIOCGRAB,(void*)1).
Please let me know if there is a better way.
Related
I'm currently working with Spring Shell. My problem is that whenever I print something to stdout, the program doesn't go back to the prompt unless the user presses the Enter button. Are there possible ways to invoke the prompt?
Max,
Since you have not provided any code, let me give you a couple of things to try. Instead of printing to stdout, you can return a string. There are disadvantages to this approach. You can try flushing stdout - System.out.flush(). Please see if either of these approaches work for you.
Sualeh.
I do process.stdin.setRawMode(true) and I get data on every keypress. Then I do process.kill(process.pid, 'SIGSTOP') and put the process into the background. When I resume the process with linux $ fg I no longer get data on every keypress but only after a carriage return. Calling setRawMode(true) again has no effect. I think this must be a bug?
Probably not very many people want to use nodejs for its raw mode processing but I posted the issue on the nodejs github and they said a work around is to setRawMode(false) and then setRawMode(true) since it will not work just setting it to true again.
Using the Turtle shell scripting library I am trying to launch a program, i.e:
shell "vim" empty
The problem is that this yields the warning Warning: Input is not from a terminal and causes Vim to lag for a few seconds before finally launching.
Questions:
Is shell the best Turtle function to launch an external program from haskell?
If so, is there any way to get around errors like the above?
You want to use functions from the process library, specifically createProcess or runProcess.
Relevant turtle thread on the issue here.
Example usage.
You could try manually setting up I/O to the vty. E.g. in bash: vim < $TTY > $TTY. I guess turtle is doing that with its own file descriptors under the hood, based on the warning, so you should be able to manually set up those redirects (or just use the command I gave via shell). You just need to make sure you've got a TTY environment var around.
I am working on a Tcl project where a certain procedure will run continuously. user can abort that procedure anytime using some Key-Combination. So basically, I need to trap the signal within Tcl code. So far, everything is done except one problem.
I am using Ctrl+Z i.e. SIGSUSP signal (SIGTSTP in case of Tcl) which technically does the job.
signal trap sigtstp onAbort
But, pressing Ctrl+Z immediately returns the Shell prompt, rest of the output from the program comes after that and when output comes to an end, no shell prompt returned (as it is already returned before). I need to press Enter again to get the prompt.
Following is the case I am refering to. You can see the prompt (polaris#ubuntu:~$) is returned in between output of the main program.
Also as output of pressing Ctrl+Z, it returned [40]+ Stopped, which is bit annoying. Can I avoid this ?
Can I avoid this whole problem using some other key-combination i.e. signal ? Or can I avoid this with Ctrl+Z also by tweking something ?
NOTE: I have tried using Ctrl+C. I got the exactly expected behavior with that. Unfortunately I can't use Ctrl+C as it is used for some other functionality.
Cz causes the shell to send the current foreground process a SIGSTOP(19). This signal cannot be caught or ignored and so your program will receive it and run the default handler. This is not killing the process as your question suggests you're trying to do. This only suspends it and you can bring it back into the foreground using fg on most modern shells.
Looks like you're out of luck. However, you might be able to rebind the keychord at the level of the shell. This is outside your program though and your end users don't have control over it. (Cf. https://superuser.com/questions/378018/how-can-i-do-ctrl-z-and-bg-in-one-keypress-to-make-process-continue-in-backgroun)
Also, if your program relies on user inputs for various actions (since you suggest that C-c does something else), perhaps you should make it a full fledged CUI application using curses or something?
In order to start gui-programs with parameters, I often find myself opening a terminal (in my case urxvt): starting the corresponding program with 'nohup' or 'disown', and then exiting the terminal. This keeps the program running as desired, but is not too comfortable. I do not use any multiplexer like tmux or screen, this would circumvent this problem. I would like to be able to start a terminal, which would automatically disown and exit after one command was issued. Any ideas how this can be achieved?
Thanks in advance
There are more elegant ways of solving this problem, but here's a solution based on what you've described:
$ (xclock &); exit
Replace xclock with the GUI program you want to run.