Sign in Join

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

Mailing lists / lazarus / 2013-08

Confusion with TProcess on Windows

4 messages · 3 people ·

Reply by email Subscribe to this list Your subscription

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

Richard Mace

Hi All,
I am baffled :)
If I open a command prompt, change to the directory which contains plink.exe and run the command:

plink -pw password command

The command works no problem, but if I do following in a TProcess I get a "flash" of a black window, then nothing!

  Process := TProcess.Create(nil);
  try
    sPSFTPFile := IncludeTrailingBackslash(ExtractFilePath(ParamStr(0))) +
'plink.exe';
    Process.Executable := sPSFTPFile;
    S := '-pw ' + Password + ' ' + Username + '@' + IPAddress + ' ' +
Command;
    Process.Parameters.Add(S);
    Process.Options := Process.Options + [poWaitOnExit];
    Process.Execute;
  finally
    Process.Free;
  end;

Any ideas?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20130808/6504b423/attachment.html>

Reply by email

Michael Van Canneyt
to Richard Mace
Richard Mace wrote 15 lines
Hi All, I am baffled :) If I open a command prompt, change to the directory which contains plink.exe and run the command: plink -pw password command The command works no problem, but if I do following in a TProcess I get a "flash" of a black window, then nothing! ? Process := TProcess.Create(nil); ? try ? ? sPSFTPFile := IncludeTrailingBackslash(ExtractFilePath(ParamStr(0))) + 'plink.exe'; ? ? Process.Executable := sPSFTPFile; ? ? S := '-pw ' + Password + ' ' + Username + '@' + IPAddress + ' ' + Command; ? ? Process.Parameters.Add(S);

Obviously this is wrong.

It should be:

With process.Parameters do
   begin
   Add('-pw');
   Add(Password);
   Add(Username+'@'+IPAddress);
   Add(Command);
   end;

Your example is specified as wrong almost verbatim in the documentation:

http://www.freepascal.org/docs-html/fcl/process/tprocess.parameters.html

Michael.

Reply by email

Ludo Brands
to Richard Mace: I am baffled :) If I open a command prompt, change to the directory which contains…
Richard Mace wrote 28 lines
Hi All, I am baffled :) If I open a command prompt, change to the directory which contains plink.exe and run the command: plink -pw password <mailto:> command The command works no problem, but if I do following in a TProcess I get a "flash" of a black window, then nothing! Process := TProcess.Create(nil); try sPSFTPFile := IncludeTrailingBackslash(ExtractFilePath(ParamStr(0))) + 'plink.exe'; Process.Executable := sPSFTPFile; S := '-pw ' + Password + ' ' + Username + '@' + IPAddress + ' ' + Command; Process.Parameters.Add(S); Process.Options := Process.Options + [poWaitOnExit]; Process.Execute; finally Process.Free; end; Any ideas?

You need to split the parameters. Parameters are the equivalent of paramstr() or argv on the receiving end. So something like:

Process.Parameters.Add('-pw');
Process.Parameters.Add(Password);
Process.Parameters.Add(Username + '@' + IPAddress);
Process.Parameters.Add('<mailto:>');
Process.Parameters.Add(Command);

Ludo

Reply by email

Richard Mace
to Ludo Brands

Michael and Ludo,
You were both spot on, that's what it was.

Thanks guys.

Rich

Ludo Brands wrote 46 lines
On 08/08/2013 08:02 AM, Richard Mace wrote: > Hi All, > I am baffled :) > If I open a command prompt, change to the directory which contains > plink.exe and run the command: > > plink -pw password <mailto:> command > > The command works no problem, but if I do following in a TProcess I get > a "flash" of a black window, then nothing! > > Process := TProcess.Create(nil); > try > sPSFTPFile := IncludeTrailingBackslash(ExtractFilePath(ParamStr(0))) > + 'plink.exe'; > Process.Executable := sPSFTPFile; > S := '-pw ' + Password + ' ' + Username + '@' + IPAddress + ' ' + > Command; > > Process.Parameters.Add(S); > Process.Options := Process.Options + [poWaitOnExit]; > Process.Execute; > finally > Process.Free; > end; > > Any ideas? > > You need to split the parameters. Parameters are the equivalent of paramstr() or argv on the receiving end. So something like: Process.Parameters.Add('-pw'); Process.Parameters.Add(Password); Process.Parameters.Add(Username + '@' + IPAddress); Process.Parameters.Add('<mailto:>'); Process.Parameters.Add(Command); Ludo -- _______________________________________________ Lazarus mailing list http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20130808/f81f8a8e/attachment.html>

Reply by email