Tprocess reading output from the commandline lazarus / 13-General ---------------------------------------------------------------------- j0x · 2010-10-25 09:51 ive followed the tutorial in here http://wiki.lazarus.freepascal.org/Executing_External_Programs i first tested this http://wiki.lazarus.freepascal.org/Executing_Exter nal_Programs#An_Improved_Example but it makes a deadlock so i tried the other one "Reading Large Output" here http://wiki.lazarus.freepascal.org/Executing_External_Pro grams#Reading_large_output but there is a error "File Not Open" it says here is the code Code: [Select]procedure TfrmMain.btnScanClick(Sender: TObject); begin      if lstInputs.Items.Count = 0 then exit;      Application.ProcessMessages;      //Hbk.CommandLine := 'HandbrakeCLI -i ' + '"' + lstInputs.Items[0] + '"' + ' -t 0';      Hbk.CommandLine := 'HandbrakeCLI -h';      Hbk.Options := [poUsePipes];      //Hbk.ShowWindow := swoShow;      Hbk.Execute;      //HbkStr.LoadFromStream(Hbk.Output);      //HbkStr.SaveToFile('HbkLog.txt');      while Hbk.running do      begin           M.SetSize(BytesRead + READ_BYTES);           n := Hbk.Output.Read((M.Memory + BytesRead)^, READ_BYTES);           if n > 0 then           begin                Inc(BytesRead,n);                Write('.');           end           else           begin                sleep(200);           end;      end;      repeat            M.SetSize(BytesRead + READ_BYTES);            n := Hbk.Output.Read((M.Memory + BytesRead)^, READ_BYTES);            if n > 0 then            begin                Inc(BytesRead,n);                Write('.');            end;      until n <= 0;      if BytesRead > 0 then Writeln;      M.SetSize(BytesRead);      HbkStr.LoadFromStream(M);      HbkStr.SaveToFile('HbkLog.txt'); end;       the last 2 code lines are the buggy ones i think, but i know that HbkStr.LoadFromStream(M); should already hold all the ouput text coming from the "HandbrakeCLI -h" console command but the HbkSaveToFile('HbkLog.txt'); cant save it so any help is appreciated again P.S. im on windows XP btw ---------------------------------------------------------------------- Leledumbo · 2010-10-25 10:38 No, the problem is (I guess) because there are two Writes there, that outputs to stdout. Make sure -WG is NOT checked in compiler option. ---------------------------------------------------------------------- j0x · 2010-10-25 10:49 Quote from: Leledumbo on October 25, 2010, 12:38:30 pmNo, the problem is (I guess) because there are two Writes there, that outputs to stdout. Make sure -WG is NOT checked in compiler option. ok it worked but how do i hide the forms console or command prompt now? ---------------------------------------------------------------------- j0x · 2010-10-25 11:22 ok another problem i encountered seems command like this for example "HandbrakeCLI -i sample.mkv -t 0" cant be read by this code im using i think it has something to do with Hbk.Options := [poUsePipes]; as HandbrakeCLI doesnt use pipes (i think) other than the command "HandbrakeCLI -h" that is use for outputting help contents. so is there any other way for me to read the output of the console commands like this "HandbrakeCLI -i sample.mkv -t 0" i googled a little bit and i saw someone use fpsystem but thats on Linux and that wont work for me as im on Windows XP thanks again for any help ---------------------------------------------------------------------- j0x · 2010-10-26 07:03 aw still no help guess there is no solution so far ---------------------------------------------------------------------- eny · 2010-10-26 07:27 Maybe HandbrakeCLI is cheating and you need this: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i   Hbk.Options := [poUsePipes, poStderrToOutPut]; ---------------------------------------------------------------------- Leledumbo · 2010-10-26 07:32 You should read HandbrakeCLI documentation ---------------------------------------------------------------------- eny · 2010-10-26 07:50 Try this in a command window: Code: [Select]HandbrakeCLI -i sample.mkv -t 0  >  log.txt Then verify the contents of the logfile log.txt. If it does not contain the information you expect, it isn't going to work with Lazarus either. ---------------------------------------------------------------------- j0x · 2010-10-26 10:34 Quote from: eny on October 26, 2010, 09:50:53 amTry this in a command window: Code: [Select]HandbrakeCLI -i sample.mkv -t 0  >  log.txt Then verify the contents of the logfile log.txt. If it does not contain the information you expect, it isn't going to work with Lazarus either. aw the log.txt file contains nothing and the output is just printed on the console so i guess thats it there is no solution at the moment, thanks for the help peeps ---------------------------------------------------------------------- Leledumbo · 2010-10-26 12:00 Quoteaw the log.txt file contains nothing and the output is just printed on the console That means the output is written to stderr instead of stdout, try reading stderr instead or use poStdErrToOutput. ---------------------------------------------------------------------- j0x · 2010-10-26 13:03 Quote from: Leledumbo on October 26, 2010, 02:00:09 pmQuoteaw the log.txt file contains nothing and the output is just printed on the console That means the output is written to stderr instead of stdout, try reading stderr instead or use poStdErrToOutput. nice your right it works now it can save the log file now, i added this code Code: [Select]Hbk.Options := [poUsePipes, poStderrToOutPut];and do this steps that you said the other day -> Compiler Options for Project Scan -> Linking -> Target OS specific options, unchecked Win32 gui application (-WG) but now my problem is how do i hide the console window (command prompt)? because if -WG is unchecked it shows it when running the program ---------------------------------------------------------------------- j0x · 2010-10-26 13:55 lol never mind it works now with enabling (-WG) the console is hidden but what i do to make the code work is i just remove the write and writeln codes as those are for console output so here is the updated code for reference Code: [Select]procedure TfrmMain.btnScanClick(Sender: TObject); begin      if lstInputs.Items.Count = 0 then exit;      Application.ProcessMessages;      Hbk.CommandLine := 'HandbrakeCLI -i ' + '"' + lstInputs.Items[0] + '"' + ' -t 0';      //Hbk.CommandLine := 'HandbrakeCLI -h';      //Hbk.Options := [poUsePipes];      Hbk.Options := [poUsePipes, poStderrToOutPut];      //Hbk.ShowWindow := swoShow;      Hbk.Execute;      //HbkStr.LoadFromStream(Hbk.Output);      //HbkStr.SaveToFile('HbkLog.txt');      while Hbk.running do      begin           M.SetSize(BytesRead + READ_BYTES);           n := Hbk.Output.Read((M.Memory + BytesRead)^, READ_BYTES);           if n > 0 then           begin                Inc(BytesRead,n);                //Write('.');           end           else           begin                sleep(200);           end;      end;      repeat            M.SetSize(BytesRead + READ_BYTES);            n := Hbk.Output.Read((M.Memory + BytesRead)^, READ_BYTES);            if n > 0 then            begin                Inc(BytesRead,n);                //Write('.');            end;      until n <= 0;      //if BytesRead > 0 then Writeln;      M.SetSize(BytesRead);      //HbkStr.LoadFromStream(M);      //HbkStr.SaveToFile('HbkLog.txt');      mmoOutputs.Lines.Clear;      mmoOutputs.Lines.BeginUpdate;      mmoOutputs.Lines.LoadFromStream(M);      mmoOutputs.Lines.EndUpdate; end;                    thanks again!!!