Sign in Join

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

Mailing lists / lazarus / 2015-12

Getting MySQL process output

11 messages · 3 people ·

Reply by email Subscribe to this list Your subscription

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

Aradeonas

[Cross posted on forum so if you want answer there : http://forum.lazarus.freepascal.org/index.php/topic,30635.0.html?]

Hi,

I want to play with MySQL process and get what ever it write to console so I write this code:

Show quoted text 6 lines
Process := TProcess.Create(nil);? with Process do? begin Executable := 'C:\Program Files (x86)\MySQL\MySQL Server 5.5\bin\mysql.exe';? ? with Parameters do? ? begin? ? ? Options := [poUsePipes];? ? ? Add('-u');? ? ? Add('root');? ? ? Add('-p'); end;? ? Execute;? ? while Process.Running do Memo1.Lines.LoadFromStream(Process.Output); ? end;

But the problem is that this will freeze because there is no output but console window write :

Enter password:

How can I get this in my application and all others?

As I said I want to work with MySQL executable and read from and write in it, So I dont want to use its library or any other DB component.

Regards, Ara

http://www.fastmail.com - Choose from over 50 domains or use your own -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20151205/84eab4d3/attachment.html>

Reply by email

Michael Van Canneyt
to Aradeonas
Aradeonas wrote 18 lines
[Cross posted on forum so if you want answer there : http://forum.lazarus.freepascal.org/index.php/topic,30635.0.html?] Hi, I want to play with MySQL process and get what ever it write to console so I write this code: > Process := TProcess.Create(nil);? with Process do? begin > Executable := 'C:\Program Files (x86)\MySQL\MySQL Server > 5.5\bin\mysql.exe';? ? with Parameters do? ? begin? ? ? Options := > [poUsePipes];? ? ? Add('-u');? ? ? Add('root');? ? ? Add('-p'); > end;? ? Execute;? ? while Process.Running do > Memo1.Lines.LoadFromStream(Process.Output); ? end; But the problem is that this will freeze because there is no output but console window write : > Enter password: How can I get this in my application and all others?

Simply said: You cannot.

As I said I want to work with MySQL executable and read from and write in it, So I dont want to use its library or any other DB component.

Specify the password on the command-line.
Then maybe you can read the output, but I doubt things will work very well, since mysql uses line editing features.

Michael.

Reply by email

Aradeonas
to Michael Van Canneyt
Simply said: You cannot.

Sure it doable. For example alternative consoles can work with mysql with help of cmd and runs cmd and then run mysql with cmd and with that they get some kind of control but I dont how to do this with Lazarus. For example if you run this without -WG command you can see that Lazarus cmd gets password message but could nopt write and it run conhost.exe. So I want to know how simulate a console.

Regards, Ara

http://www.fastmail.com - Send your email first class -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20151205/1e288148/attachment.html>

Reply by email

Michael Van Canneyt
to Aradeonas
Aradeonas wrote 7 lines
> Simply said: You cannot. Sure it doable. For example alternative consoles can work with mysql with help of cmd and runs cmd and then run mysql with cmd and with that they get some kind of control but I dont how to do this with Lazarus. For example if you run this without -WG command you can see that Lazarus cmd gets password message but could nopt write and it run conhost.exe. So I want to know how simulate a console.

Simple Loop:
- Read from program output
- interpret the output and
- write to program input.
That's all the "general" advice we can give.

Don't ever use LoadFromStream.
It will try to load all data that is outputted by the program, and does not give you the possibility to write input.

Michael.

Reply by email

Aradeonas
to Michael Van Canneyt
Simple Loop:

- Read from program output
- interpret the output and
- write to program input. That's all the "general" advice we can give.

Yea sure I do this and I have no problem with simple CMD programs. Problem is programs like MySQL that can be run from one line command and need reading and writing. When you run this command : '"C:\Program Files (x86)\MySQL\MySQL Server 5.5\bin\mysql.exe" -u root -p'; You will get nothing in the output, it is locked and you even cant call NumByteAvailable but interesting is if you remove -WG param you can see Enter password:?it will write in CMD that opens with program it self from Lazarus.

Regards, Ara

http://www.fastmail.com - Same, same, but different... -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20151205/6c370d1a/attachment.html>

Reply by email

Michael Van Canneyt
to Aradeonas
Aradeonas wrote 13 lines
> Simple Loop: - Read from program output - interpret the output and - write to program input. That's all the "general" advice we can give. Yea sure I do this and I have no problem with simple CMD programs. Problem is programs like MySQL that can be run from one line command and need reading and writing. When you run this command : '"C:\Program Files (x86)\MySQL\MySQL Server 5.5\bin\mysql.exe" -u root -p'; You will get nothing in the output, it is locked and you even cant call NumByteAvailable but interesting is if you remove -WG param you can see Enter password:?it will write in CMD that opens with program it self from Lazarus.

What is the -WG param ? I could not find it in the documentation.

I also don't understand why you don't specify the password on the command-line, then you would not have these problems. If you are afraid that it will be visible in the task list, just set the MYSQL_PWD and USER environment variables in TProcess.

All in all, I suspect you would probably be better off using the mysql library. The mysql command is just a front-end to that.

Michael.

Reply by email

Aradeonas
to Michael Van Canneyt
What is the -WG param ? I could not find it in the documentation.

Win32 GUI application in compiler option> conf and target

If you are afraid that it will be visible in the task list, just set the MYSQL_PWD and USER environment variables in TProcess.

Good point.

All in all, I suspect you would probably be better off using the mysql library.

The mysql command is just a front-end to that. As I said in my first question is not just a MySQL problem, for this case I need to connect to mysql cmd not library and for that I need to communicate with it and write SQl query and send and then receive the result. I just dont know how read its output,its not like a simple CMD program that you run and get the output simply.

Regards, Ara

http://www.fastmail.com - Faster than the air-speed velocity of an unladen european swallow -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20151205/658aa1eb/attachment-0001.html>

Reply by email

Michael Van Canneyt
to Aradeonas
Aradeonas wrote 13 lines
> What is the -WG param ? I could not find it in the documentation. Win32 GUI application in compiler option> conf and target > If you are afraid that it will be visible in the task list, just set > the MYSQL_PWD and USER environment variables in TProcess. Good point. > All in all, I suspect you would probably be better off using the mysql > library. The mysql command is just a front-end to that. As I said in my first question is not just a MySQL problem, for this case I need to connect to mysql cmd not library and for that I need to communicate with it and write SQl query and send and then receive the result. I just dont know how read its output,its not like a simple CMD program that you run and get the output simply.

Did you use the poNoConsole option ?

Michael.

Reply by email

Aradeonas
to Michael Van Canneyt
Did you use the poNoConsole option ?

Yes and NumByteAvailable ?is 0 but it write "Enter Password" message in console. I can understand why this message goes in Lazarus output or wherever except output of TProcess.

Regards, Ara

http://www.fastmail.com - Access all of your messages and folders wherever you are -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20151205/bbb3ce5a/attachment.html>

Reply by email

Unknown author
to Aradeonas
Aradeonas wrote 5 lines
Did you use the poNoConsole option ? Yes and NumByteAvailable is 0 but it write "Enter Password" message in console. I can understand why this message goes in Lazarus output or wherever except output of TProcess.

is it maybe sent via something other than STDOUT? STDERR perhaps? for security reasons maybe?

NOTE: No off-list assistance is given without prior approval. *Please keep mailing list traffic on the list* unless private contact is specifically requested and granted.

Reply by email

Aradeonas
to Unknown author
is it maybe sent via something other than STDOUT? STDERR perhaps? for security

reasons maybe? Nothing! :|

Show quoted text 7 lines
Process := TProcess.Create(nil);? with Process do? begin? ? Executable := '"C:\Program Files (x86)\MySQL\MySQL Server 5.5\bin\mysql.exe" -u root -p';? ? with Parameters do? ? begin? ? ? Options := [poUsePipes, poNoConsole];? ? end;? ? ? Execute;? Sleep(1000); WriteLn(Process.Output.NumBytesAvailable); // will be 0 but it write "Enter password" ? WriteLn(Process.Stderr.NumBytesAvailable); ?? // will be 0 but it write "Enter password" ? end;

Regards, Ara

http://www.fastmail.com - IMAP accessible web-mail -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20151205/a55d9625/attachment.html>

Reply by email