You are not logged in.

#1 2009-09-10 17:55:48

pepeapepepe
Member
From: Buenos Aires, Argentina
Registered: 2009-05-13
Posts: 36

[Solved]Sending Characters to a process

Hi,

    I'm trying to stop (nicely) a xterm running a ncmpc from another termial. For scrpiting purposes.

   So i thought it would be enought to send a 'q' character trought stdin.

   this is what i'm testing

pc -C ncmpc   # to grab the PID

once i've got the PID i try

echo -n q > /proc/PID/fd/0

but the progrma doesn't exits. (it prints the q on stdout)

Could somebody give advice on how to do this?

  1) is this the best way ?(maybe kill -STOP PID is not bad if ncmpc handles it well)

  2) or how do i echo the q?

regards

Last edited by pepeapepepe (2009-09-10 19:06:29)


.--.-.... --. .-.-.-..-.-..--....- .- .-...-... --..-..-... -.-.----. ..-.. ...------....-...-.-----..-- .-....---.-..- --. .-.-.-..-.-.--- .-...-... --..-..-... -.-.----. .-...- -......-...-...-..-..-

Offline

#2 2009-09-10 18:32:07

Procyon
Member
Registered: 2008-05-07
Posts: 1,819

Re: [Solved]Sending Characters to a process

fd/1 doesn't work either.

killall ncmpc should work

With gdb you can run C code in the application, like ungetch('q')
$ gdb ncmpc PID
(gdb) call ungetch('q')
(gdb) detach

I'm not sure if there's a more convenient way for a bash script, but with a gdb script file it seems to work
call ungetch('q')
detach
quit

and run
gdb ncmpc $(pgrep ncmpc) --command=gdbsendq.txt

Offline

#3 2009-09-10 19:08:24

pepeapepepe
Member
From: Buenos Aires, Argentina
Registered: 2009-05-13
Posts: 36

Re: [Solved]Sending Characters to a process

ok,

   it worked fine,
   that's a cool gdb feature i didn't knew about tongue

thaks


.--.-.... --. .-.-.-..-.-..--....- .- .-...-... --..-..-... -.-.----. ..-.. ...------....-...-.-----..-- .-....---.-..- --. .-.-.-..-.-.--- .-...-... --..-..-... -.-.----. .-...- -......-...-...-..-..-

Offline

Board footer

Powered by FluxBB