Archiv verlassen und diese Seite im Standarddesign anzeigen : Zeichen in einen Background-Prozess pipen
Hi,
eigentlich ganz einfach:
ich habe einen Prozess, der im hintergrund läuft und dort eine eingabe erwartet. Meint ihr ich kann da was reinpipen ?
irgendwie so: ./testtool <&whatever ?
BLUESCREEN3D
13-03-2008, 17:36
Du kannst eine Named Pipe benutzen:
mkfifo my_pipe
cat < my_pipe &
echo irgendwas > my_pipe
#nach der echo-Zeile beendet sich cat, da die Eingabe endet
rm my_pipe
Ah ja, das mkfifo kannte ich gar nicht. Ich habe jetzt mal folgendes gemacht, da ich nicht genau wusste, wo ich jetzt das Programm starten soll, in welches gepipet wird:
cat < mypipe & echo ./meinproggi > mypipe & echo admin >> mypipe; echo admin >> mypipe; echo >> mypipe
,denn ich muss 2x "admin" & dann 1x enter eintippen, aber zum Erfolg hat mich das nicht gebracht. Das Kommando kommt zumindest sofort zurück.
Soweit bin ich jetzt:
1047 mkfifo pipe
1048 echo admin >> pipe &
1049 echo admin >> pipe &
1050 echo >> pipe &
1051 ./myproggi < pipe
dann kommt aber folgendes:
Error: Need to prompt for the password but cannot prompt because the process is running in the background.
Das kommt zwar klar vom meinem Proggi (was ich leider nicht änder kann) aber jetzt muss ich das ding noch in der foreground holen, nur
./myproggi &fg < pipe funktioniert leider nicht.
Weiß einer da weiter ?
Moin,
...
Error: Need to prompt for the password but cannot prompt because the process is running in the background.
Das klappt schon:
jan@jack:~/tmp/prompt> cat back.sh
#! /bin/bash
read -p "Enter password: " inp
read -p "Re-enter password: " inp2
echo "got password $inp $inp2"
jan@jack:~/tmp/prompt> mkfifo pfeife
jan@jack:~/tmp/prompt> echo "a
a
" >pfeife &
[1] 8160
jan@jack:~/tmp/prompt> ./back.sh <pfeife &
[2] 8228
jan@jack:~/tmp/prompt> got password a a
[1]+ Done echo "a
a
" >pfeife
[2]+ Done ./back.sh <pfeife
jan@jack:~/tmp/prompt> rm pfeife
Es gibt aber ein Problem, wenn Dein Programm nicht von stdin liest, sondern direkt vom Terminal (das tun viele Programme, die Passwörter abfragen). Hier könnte Dir vielleicht "expect" helfen: http://www.faqs.org/faqs/unix-faq/faq/part3/section-9.html
Jan
Powered by vBulletin® Version 4.2.5 Copyright ©2025 Adduco Digital e.K. und vBulletin Solutions, Inc. Alle Rechte vorbehalten.