Sign in Join

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

Mailing lists / fpc-pascal / 2009-01

TProcess.CommandLine > 255 fails

11 messages · 6 people · –

Reply by email Subscribe to this list Your subscription

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

T.Guilleminot

Hi,

I use TProcess.CommandLine very often and I discovered that it seems limited to 255 chars.
Does anyone know how to workaround this limitation ? Thanks

Tom

Tomas Hajny
to T.Guilleminot

On 2 Jan 09, at 22:15, T.Guilleminot wrote:

Hi,

I use TProcess.CommandLine very often and I discovered that it seems limited to 255 chars. Does anyone know how to workaround this limitation ?

Which target/operating system? I assume that your code using TProcess is compiled with {$H+} or in {$MODE DELPHI} (or that you declared the respective variables as ansistrings explicitly?

Tomas

T.Guilleminot

I'm on Linux. I've no idea how TProcess is compiled actually. I discovered the problem with command passed into an ansistring and to test I also reproduced with a GTK_Entry Text (dont know how it is passed internally)
Thanks.

Show quoted text 8 lines
I use TProcess.CommandLine very often and I discovered that it seems limited to 255 chars. Does anyone know how to workaround this limitation ? Which target/operating system? I assume that your code using TProcess is compiled with {$H+} or in {$MODE DELPHI} (or that you declared the respective variables as ansistrings explicitly? Tomas
T.Guilleminot
2.2.x or 2.3.x?

I used the 2.2.0 (provided by Ubuntu repositories). Then I just upgraded and tested in 2.2.2-8 but problem is still the same :(

Jonas Maebe
to T.Guilleminot
T.Guilleminot wrote 5 lines
> 2.2.x or 2.3.x? I used the 2.2.0 (provided by Ubuntu repositories). Then I just upgraded and tested in 2.2.2-8 but problem is still the same :(

Please provide a compilable program that demonstrates the problem.

Jonas

T.Guilleminot
Please provide a compilable program that demonstrates the problem. Jonas

Create a myini.ini file containing :

[TEST]
CMD_OK=echo 'Hello !'
CMD_NOT_OK=mencoder dvb://M6 -sws 9 -of lavf -lavfopts format=mp4 -vf scale=480:320,dsize=480:320,harddup -ovc x264 -x264encopts bitrate=500:vbv_maxrate=1500:vbv_bufsize=2000:nocabac:me=umh:trellis=1:level_idc=30:global_header:threads=2:pass=1:turbo -oac faac -faacopts mpeg=4:object=2:br=160:raw -channels 2 -srate 48000 -o test.mp4

Then the program :

program Pb_TProcess_255;
uses Process, inifiles;
var
  Ini_File : TIniFile;
  CMD_OK, CMD_NOT_OK : ansistring;
// Read INI File
Procedure Read_Parameters_File;
begin
  Ini_File := TIniFile.Create('./myini.ini');
  with Ini_File do begin
    CMD_OK:=ReadString('TEST', 'CMD_OK', 'error');
    CMD_NOT_OK:=ReadString('TEST', 'CMD_NOT_OK', 'error');
        writeln;
    writeln(' CMD_OK : '+CMD_OK);
    writeln;
        writeln(' CMD_NOT_OK : '+CMD_NOT_OK);
        writeln;
  end;
end;
// Run an OS Command and *Wait* his Completion to Continue
procedure Run_Command_Wait(TheCommand : string); cdecl;
var
  AProcess: TProcess;
Begin
  AProcess := TProcess.Create(nil);
  AProcess.CommandLine := TheCommand;
  AProcess.Options := AProcess.Options+ [poWaitOnExit];
  AProcess.Execute;
  AProcess.Free;
end;
// Main Program
begin
  Read_Parameters_File;
    Run_Command_Wait(CMD_OK);
    writeln;
    Run_Command_Wait(CMD_NOT_OK);
end.

The first command runs OK but the 2nd one reports an error and shows the 255th character :

Hello !

MEncoder 2:1.0~rc2-0ubuntu17 (C) 2000-2007 MPlayer Team CPU: Intel(R) Core(TM)2 CPU 6600 @ 2.40GHz (Family: 6, Model: 15, Stepping: 6)
CPUflags: Type: 6 MMX: 1 MMX2: 1 3DNow: 0 3DNow2: 0 SSE: 1 SSE2: 1 Compiled with runtime CPU detection.
-faaco is not an MEncoder option
Exiting... (error parsing command line)

THanks.

Joost van der Sluis
to T.Guilleminot

Op zondag 04-01-2009 om 12:31 uur [tijdzone +0100], schreef T.Guilleminot:

procedure Run_Command_Wait(TheCommand : string); cdecl;

This 'string' is of the type shortstring, and thus will truncate your string to 255 characters.

Change it in ansistring or add {$H+} to the beginning of your program.

Joost.

Jürgen Hestermann
to Joost van der Sluis: Op zondag 04-01-2009 om 12:31 uur [tijdzone +0100], schreef T.Guilleminot: This 'string'…
> procedure Run_Command_Wait(TheCommand : string); cdecl; This 'string' is of the type shortstring, and thus will truncate your string to 255 characters. Change it in ansistring or add {$H+} to the beginning of your program.

I would advice to declare "TheCommand : AnsiString" instead of changing the compiler switch because then it's independend from such changes/settings. Especially, when such switches change other things too and one day you may need some of these other things and get the side effect of changing the string type too.

In general I would advice not to use the generic types "string" (nor "integer") at all. It only leads to confusion because noone knows (or is aware) of what type is meant in particular. Why not use the strings that is needed?

Jürgen Hestermann.

T.Guilleminot

Thanks ! Changing "TheCommand" to ansistring seems work ! Did not think about this simple thing.
I'm testing more deeply. Thanks again.