Re: 'call' function disables echoing input
Hi Alex, > So, something must still be wrong. I just never noticed it because I > only called non-interactive processes (except 'vim'). But that is my point - vim goes to a lot of effort to handle the STOP and CONT signals and get the terminal handling right. I have created apps similar to vim - and the "onus" is on the app to do it right, not the calling shell! The calling shell does have some things to do, but as you point out: vim and picolisp work well together! That can only happen if picolisp is basically doing it's part right. (look up onus: Beweislast, Verspflichtung) Cheers! - Rand -- UNSUBSCRIBE: mailto:picol...@software-lab.de?subject=unsubscribe
Re: 'call' function disables echoing input
Hi Randall, > Do shells really? A simple case of the opposite: start vim, kill -9 > from another shell, and you have to type "stty sane". I think it is > more up to the application to save and restore. That's true. What I meant, however, was the handling of terminal I/O and the 'stop' signal in processes spawned by this shell. When you invoke 'vim' in PicoLisp, it behaves correctly: Terminal I/O obviously works (as you can edit in 'vim'), and if you hit Ctrl-Z 'vim' is stopped and control is back at PicoLisp (i.e. our "shell"). You are now in PicoLisp at a special prompt ('+'). When you hit Enter hat that prompt, 'vim' gets a 'cont' signal and you can continue editing'. Otherwise, if you hit Ctrl-Z again at the '+' prompt, you drop back into the bash. There back to PicoLisp with 'fg', and Enter to 'vim'. So this is the behavior I intended. However, in Kriangkrai's situation, the spawned process (a shell) does not receive any terminal input. : (call 'sh "-c" "echo -n 'name: '; read name; echo $name") This is not only a problem of raw mode - this can be handled with setCooked() and setRaw() at proper places in doCall() - but of keyboard input in general. That is, the 'read' in the shell immediately receives EOF and returns. I can get it to work if I take out all the "set process group" and "set terminal foreground process group" handling from doCall(). But then neither 'vim' nor the signal handling work any longer. So, something must still be wrong. I just never noticed it because I only called non-interactive processes (except 'vim'). Cheers, - Alex -- UNSUBSCRIBE: mailto:picol...@software-lab.de?subject=unsubscribe
Re: 'call' function disables echoing input
Hi Alex, Do shells really? A simple case of the opposite: start vim, kill -9 from another shell, and you have to type "stty sane". I think it is more up to the application to save and restore. Although, picolisp does bring surprises, whether you start with dbg.l and *Dbg on or not. But I think the way it works is ok, there are real advantages, once you understand it. Cheers - Rand On Fri, May 8, 2009 at 2:35 PM, Alexander Burger wrote: > Yes. I hope in time we'll get 'call' right. It must be possible, because > shells do the same. -- UNSUBSCRIBE: mailto:picol...@software-lab.de?subject=unsubscribe
Re: 'call' function disables echoing input
Hi Kriangkrai, > Many thanks! Now it works, though it would be much better to have > 'call' working correctly. Yes. I hope in time we'll get 'call' right. It must be possible, because shells do the same. Cheers, - Alex -- UNSUBSCRIBE: mailto:picol...@software-lab.de?subject=unsubscribe
Re: 'call' function disables echoing input
Hi Alex, Many thanks! Now it works, though it would be much better to have 'call' working correctly. (de shell* (S) # run shell command with interactive input (let Raw (raw) (unless Raw (raw T)) (let Opts '(icrnl icanon iexten echo echoe echok echoctl echoke) #! use (call "stty") to see what options need to be toggled (call "sh" "-c" (pack "stty " (glue " " Opts) "; " S "; stty -" (glue " -" Opts))) (unless Raw (raw NIL)) ))) (shell* "echo -n 'name: '; read name; echo $name") Best regards, KS -- UNSUBSCRIBE: mailto:picol...@software-lab.de?subject=unsubscribe
Re: 'call' function disables echoing input
Hi Kriangkrai, > I've found a way to make it works, but only when I load the file in > the PicoLisp prompt, not when the file is loaded from command-line > argument. > ... > Do you have more hint? So the difference must be whether the console was set to raw mode or not. When the PicoLisp command line prompt appears, the function 'key' is called internally by the line editor. Key calls setRaw() (basically the same as (raw T)). When you call a script directly, the console is not (yet) set to raw mode. Perhaps you should experiment with (raw NIL) and (raw T)? I also did some more experiments this morning in the code of 'call', but without success. If I take out the setpgid() and tcsetpgrp() calls, either 'vim' does not work any more, or SIGSTOP will not be handled correctly :-( Cheers, - Alex -- UNSUBSCRIBE: mailto:picol...@software-lab.de?subject=unsubscribe
Re: 'call' function disables echoing input
Hi Alex, I've found a way to make it works, but only when I load the file in the PicoLisp prompt, not when the file is loaded from command-line argument. > /tmp/t.l (de shell* (S) # run shell command with interactive input # NB: use (call "stty") to see what options need to be toggled (let Opts '(icrnl icanon iexten echo echoe echok echoctl echoke) (call "sh" "-c" (pack "stty " (glue " " Opts) "; " S "; stty -" (glue " -" Opts))) )) (shell* "echo -n 'name: '; read name; echo $name") % ./p dbg.l : (load "/tmp/t.l") name: abc abc -> T : (everything still works) % ./p dbg.l /tmp/t.l (just blank, not work!) ^C Do you have more hint? Best regards, KS -- UNSUBSCRIBE: mailto:picol...@software-lab.de?subject=unsubscribe
Re: 'call' function disables echoing input
Hi Kriangkrai, > The reason is that I want to do scripting in PicoLisp (thank you so > much for sharing it :-). Sometimes I need to call a shell script, You are welcome :-) > which requires "interactive" input (and that I want it to still be > "interactive"). OK, I understand. > Nothing occur when running: > : (vi "file") > -> NIL Sorry, this was my fault. The 'vi' function works only with symbols, not with file names. : (vi 'vi) > But using (call 'vi "file") works fine. OK. > Calling > : (raw NIL) (call 'sh "-c" "echo -n 'name: '; read name; echo $name") (ra= > w T) > does not work too on my system. Yep, I tried a similar thing with calling setCooked() in doCall(). It does not help. But if I take out all that terminal control group stuff out of doCall() (see the '// ' comments) if ((pid = fork()) == 0) { // setpgid(0,0); execvp(av[0], av); execError(av[0]); } i = 0; do free(av[i]); while (++i < ac); if (pid < 0) err(ex, NULL, "fork"); // setpgid(pid,0); // if (Termio) //tcsetpgrp(0,pid); for (;;) { while (waitpid(pid, &res, WUNTRACED) < 0) { if (errno != EINTR) err(ex, NULL, "wait pid"); if (Signal) sighandler(ex); } //if (Termio) // tcsetpgrp(0,getpgrp()); if (!WIFSTOPPED(res)) return res == 0? T : Nil; load(NULL, '+', Nil); //if (Termio) // tcsetpgrp(0,pid); kill(pid, SIGCONT); } it works, without echoing the input, though. Then, when I then put a (raw NIL) before the (call ..) and a (raw T) after, the echo (and Enter as input terminator) also works. However, then the terminal STOP signal does not work correctly any more. The intended behavior was that upon Ctrl-Z in the executing program (e.g. 'vi') it drops back to the PicoLisp '+' prompt, and when you hit Ctrl-Z there again, you'll leave PicoLisp and are back on the Unix shell. So I don't remember completely at the moment, but all this terminal stuff had some purpose. What would be the correct way here? Anybody firm in such an exercise? (Randall?) Cheers, - Alex -- UNSUBSCRIBE: mailto:picol...@software-lab.de?subject=unsubscribe
Re: 'call' function disables echoing input
Hi Alex, The reason is that I want to do scripting in PicoLisp (thank you so much for sharing it :-). Sometimes I need to call a shell script, which requires "interactive" input (and that I want it to still be "interactive"). Nothing occur when running: : (vi "file") -> NIL But using (call 'vi "file") works fine. Calling : (raw NIL) (call 'sh "-c" "echo -n 'name: '; read name; echo $name") (ra= w T) does not work too on my system. I notice that (raw NIL) does nothing. : (raw NIL) -> NIL : (raw) -> T Best regards, KS On Thu, May 7, 2009 at 7:08 PM, Alexander Burger wrot= e: > Hi Kriangkrai, > >> When I run: (call 'sh "-c" "echo -n 'name: '; read name; echo $name") >> It outputs "name :" and waits for input. I type something (e.g. "abc") >> but nothing echo. I press the Enter key, nothing happens. I press >> Ctrl-J, then it prints "abc". > > Hmm, I cannot reproduce it in the same way, but I recognize that this is > a problem in general. In both cases when I either run it without line > editing: > > =A0 $ bin/picolisp > =A0 : (call 'sh "-c" "echo -n 'name: '; read name; echo $name") > =A0 name: > =A0 -> T > > or with: > > =A0 $ ./p dbg.l > =A0 : (call 'sh "-c" "echo -n 'name: '; read name; echo $name") > =A0 name: > =A0 -> T > > it immediately returns, meaning that the 'read' got EOF immediately. Not > sure if this is correct behavior. > > On the other hand, things like > > =A0 : (vi "file") > > work well. How is that in your case? > > >> It works fine, but after returning to PicoLisp prompt, line editing brok= e. >> How to solve this this problem? > > We could either insert setCooked() and setRaw() calls to the child part > of doCall() (not tried), or do it on the Lisp level: > > =A0 : (raw NIL) (call 'sh "-c" "echo -n 'name: '; read name; echo $name")= (raw T) > > This, however, does not show any different bahavior on my system. > > > What is actually the purpose of that call? > > Cheers, > - Alex > -- > UNSUBSCRIBE: mailto:picol...@software-lab.de?subject=3dunsubscribe > -- UNSUBSCRIBE: mailto:picol...@software-lab.de?subject=unsubscribe
Re: 'call' function disables echoing input
Hi Kriangkrai, > When I run: (call 'sh "-c" "echo -n 'name: '; read name; echo $name") > It outputs "name :" and waits for input. I type something (e.g. "abc") > but nothing echo. I press the Enter key, nothing happens. I press > Ctrl-J, then it prints "abc". Hmm, I cannot reproduce it in the same way, but I recognize that this is a problem in general. In both cases when I either run it without line editing: $ bin/picolisp : (call 'sh "-c" "echo -n 'name: '; read name; echo $name") name: -> T or with: $ ./p dbg.l : (call 'sh "-c" "echo -n 'name: '; read name; echo $name") name: -> T it immediately returns, meaning that the 'read' got EOF immediately. Not sure if this is correct behavior. On the other hand, things like : (vi "file") work well. How is that in your case? > It works fine, but after returning to PicoLisp prompt, line editing broke. > How to solve this this problem? We could either insert setCooked() and setRaw() calls to the child part of doCall() (not tried), or do it on the Lisp level: : (raw NIL) (call 'sh "-c" "echo -n 'name: '; read name; echo $name") (raw T) This, however, does not show any different bahavior on my system. What is actually the purpose of that call? Cheers, - Alex -- UNSUBSCRIBE: mailto:picol...@software-lab.de?subject=unsubscribe
'call' function disables echoing input
Hi, The 'call' function seems to disable echo. Also, The Enter key does not end an input line, Ctrl-J must be used instead. When I run: (call 'sh "-c" "echo -n 'name: '; read name; echo $name") It outputs "name :" and waits for input. I type something (e.g. "abc") but nothing echo. I press the Enter key, nothing happens. I press Ctrl-J, then it prints "abc". If I instead use: (call 'sh "-c" "stty sane; echo -n 'name: '; read name; echo $name") It works fine, but after returning to PicoLisp prompt, line editing broke. How to solve this this problem? Thanks, KS -- UNSUBSCRIBE: mailto:picol...@software-lab.de?subject=unsubscribe