Results 1 to 7 of 7

Thread: How to execute commands using Simba & Lape.

  1. #1
    Join Date
    May 2012
    Location
    Moscow, Russia
    Posts
    653
    Mentioned
    35 Post(s)
    Quoted
    102 Post(s)

    Default How to execute commands using Simba & Lape.

    Hey guys. Many users do not know about the class TProcess. That class allows you to launch an external application in Lazarus. And, it also exported to Lape. Today I'll show you how to use it. How does this help you? You are only limited by your imagination.

    So, my test form looks:
    w5qyEyTb.png

    And then we use the functional of TProcess to execute an external program and get it output:

    Simba Code:
    procedure RunCommand(Cmd: string; Lines: TStrings);
    var
      AProcess: TProcess;
      Buf: array [1..BUFSIZE] of char;
      I, Count: longint;
      ss: string;
    begin
      Lines.Clear;
      AProcess.Init(nil);
      try
        AProcess.SetCommandline(Cmd);
        AProcess.setOptions([poUsePipes, poNoConsole]);
        AProcess.execute;
        repeat
          count := AProcess.GetOutput().Read(buf, BufSize);
          for I := 1 to count do
            ss := ss + buf[i];
        until Count = 0;
        Lines.Add(ss);
      finally
        AProcess.Free;
      end;
    end;
    After call of this function with params like 'netstat -an' we get the result:
    w5qyEyTa.png

    Well, after that, as I said - you can only limit is your imagination. I showed you the mechanism by which it is possible to significantly increase the scope of the Simba using.
    My test script can be found in attachment.

    Thank you for attention!

    Cheers,
    Cynic.

    PS:

    Reference of TProcess methods:
    http://www.freepascal.org/docs-html/.../tprocess.html

    FPC wiki of TProcess:
    http://wiki.freepascal.org/Executing...grams#TProcess
    Attached Files Attached Files
    Per aspera ad Astra!
    ----------------------------------------
    Slow and steady wins the race.

  2. #2
    Join Date
    Nov 2011
    Location
    England
    Posts
    3,052
    Mentioned
    286 Post(s)
    Quoted
    1084 Post(s)

    Default

    Should note that CommandLine is deprecated, Should really be using executable & parameters which sadly isn't as simple but isn't too bad.
    <Olly> wtf slacky
    <Olly> this looks like windows
    <Olly> not ubuntu
    <slacky> WHAT DIDN'T YOU GET ABOUT: <slacky> anyways. later
    <slacky> do I have to log of irc to get to play MC?
    <slacky> That sounds like a plan
    * slacky has quit (Quit: Leaving)


  3. #3
    Join Date
    Mar 2015
    Posts
    434
    Mentioned
    21 Post(s)
    Quoted
    209 Post(s)

    Default

    This brings up a question on whether or not there is a parameter to automate "play" button in simba so that we could just call on a script.

    May sound useless but there's multiple uses here;
    You can have a script launch into another script which may begin you in starting another account to start training or whatever - then have that script launch the other script once it's finished to log back into your other account ultimately creating a loop. Obviously would require a flawless script but..
    I'm specifically curious for OgLib - as closing simba and starting a new instance helps free up resources and get's rid of the lag that accumulates over time.

    Edit: Found what I was looking for https://villavu.com/forum/showthread...ighlight=batch
    Last edited by Clutch; 02-15-2016 at 04:12 AM.

  4. #4
    Join Date
    Dec 2007
    Posts
    2,107
    Mentioned
    69 Post(s)
    Quoted
    578 Post(s)

    Default

    @Clutch;

    Gravedig? Search before you bump.

  5. #5
    Join Date
    Mar 2015
    Posts
    434
    Mentioned
    21 Post(s)
    Quoted
    209 Post(s)

    Default

    Quote Originally Posted by Kasi View Post
    @Clutch;

    Gravedig? Search before you bump.
    Just trying to bump up my post count.

  6. #6
    Join Date
    Dec 2007
    Posts
    2,107
    Mentioned
    69 Post(s)
    Quoted
    578 Post(s)

    Default

    Quote Originally Posted by Clutch View Post
    Just trying to bump up my post count.
    y ?

  7. #7
    Join Date
    Jan 2008
    Posts
    32
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Hello

    I tried this with the latest simba version but it crashes when I run a command ?
    Anyone knows a fix for this ?

    //EDIT: Got it already. It still works perfect It just crashed because of the command I used (infinite loop in repeat)
    Last edited by penguII; 12-04-2018 at 10:57 AM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •