Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2013-01

How can a program executing a command via TProcess detect an input prompt and create a graphical dialog for the input?

8 messages · 5 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Frank Church

How can a Lazarus/FPC program that is executing a command via TProcessdetect an input prompt and create a graphical dialog for the input?

e.g. say I execute an ssh command via TProcess which requires a password to be input - how could it detect it, prompt for it with a graphical dialog and pass it on for the command to continue?

Frank Church ======================= http://devblog.brahmancreations.com -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20130101/099f3944/attachment.html>

Reply by email

leledumbo
to Frank Church

There's no such a way AFAIK, you have to know exactly what your program is executing. Therefore you have to always give the graphical input dialog (and it's up to you when to show it, before or during execution).

Reply by email

Michael Van Canneyt
to Frank Church: How can a Lazarus/FPC program that is executing a command via TProcessdetect an input…
Frank Church wrote 5 lines
How can a Lazarus/FPC program that is executing a command via TProcess detect an input prompt and create a graphical dialog for the input? e.g. say I execute an ssh command via TProcess which requires a password to be input - how could it detect it, prompt for it with a graphical dialog and pass it on for the command to continue?

There is no way to do this in general.

There are some unix tools that attempt to do this ('expect'), but all of them require some form of script, taylored to the tools that you want to use it for.

Michael.

Reply by email

Mark Morgan Lloyd
to Michael Van Canneyt
Michael Van Canneyt wrote 16 lines
On Tue, 1 Jan 2013, Frank Church wrote: > > How can a Lazarus/FPC program that is executing a command via TProcess > detect an input prompt and create a graphical dialog for the input? > > e.g. say I execute an ssh command via TProcess which requires a > password to be input - how could it detect it, prompt for it with a > graphical dialog and pass > it on for the command to continue? There is no way to do this in general. There are some unix tools that attempt to do this ('expect'), but all of them require some form of script, taylored to the tools that you want to use it for.

Considering the particular case of SSH, I think there's a related daemon which can detect whether sshd is asking for a passphrase and present a dialog(ue). I've not used it, and can't remember the extent to which it e.g. worked across networked systems.

I think the question needs to be clarified: would the requirement be better served by (a) finding some way for an alternative daemon or API to display the prompt or (b) investigating how to hook the TProcess child's request for input.

Mark Morgan Lloyd markMLl .AT. telemetry.co .DOT. uk [Opinions above are the author's, not those of his employers or colleagues]

Reply by email

Hans-Peter Diettrich
to Mark Morgan Lloyd
Considering the particular case of SSH, I think there's a related daemon which can detect whether sshd is asking for a passphrase and present a dialog(ue). I've not used it, and can't remember the extent to which it e.g. worked across networked systems.

Doesn't ssh have according parameters, so that it must not ask the user?

I think the question needs to be clarified: would the requirement be better served by (a) finding some way for an alternative daemon or API to display the prompt or (b) investigating how to hook the TProcess child's request for input.

I'd write a new GUI around the worker code, so that ssh (or whatsoever) can be used as a library in every program. I did this already for tools like gzip, so that these can be used in my own console or GUI programs.

DoDi

Reply by email

Mark Morgan Lloyd
to Hans-Peter Diettrich
Hans-Peter Diettrich wrote 8 lines
Mark Morgan Lloyd schrieb: > Considering the particular case of SSH, I think there's a related > daemon which can detect whether sshd is asking for a passphrase and > present a dialog(ue). I've not used it, and can't remember the extent > to which it e.g. worked across networked systems. Doesn't ssh have according parameters, so that it must not ask the user?

That wasn't what I had in mind though. See ssh-agent.

Mark Morgan Lloyd markMLl .AT. telemetry.co .DOT. uk [Opinions above are the author's, not those of his employers or colleagues]

Reply by email

Frank Church
to Frank Church: How can a Lazarus/FPC program that is executing a command via TProcessdetect an input…
Frank Church wrote 11 lines
How can a Lazarus/FPC program that is executing a command via TProcessdetect an input prompt and create a graphical dialog for the input? e.g. say I execute an ssh command via TProcess which requires a password to be input - how could it detect it, prompt for it with a graphical dialog and pass it on for the command to continue? -- Frank Church ======================= http://devblog.brahmancreations.com

After further consideration I think what I am thinking of is a TProcess like object that emulates a console, so it "types" the command and receives input as well as prompts. Is there an FPC library that does something like that?

Frank Church ======================= http://devblog.brahmancreations.com -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20130103/11960e0b/attachment.html>

Reply by email

Hans-Peter Diettrich
to Frank Church
After further consideration I think what I am thinking of is a TProcess like object that emulates a console, so it "types" the command and receives input as well as prompts. Is there an FPC library that does something like that?

You don't need a console. Simply create a bidirectional pipe, or two unidirectional ones, and connect it to the stdin/stdout of the process. Then parse what the process outputs, and when you find the prompt, send it your input.

DoDi

Reply by email