Jump to content

Help with Scripting for an External CLI Program - eac3to.exe


dandino
 Share

Recommended Posts

Hi Guys,

I am attempting to design a front end GUI for a CLI program by the name of eac3to.exe. The problem as I see it is that this program sends all of it's output to a cmd window. This is giving me no end of trouble because I need to get a lot of this output into a GUI window. This sounds easy enough, but I am begining to wonder whether I have found one of AutoIt's limitations?
I can use the Run() function with a windows internal command such as Dir and then get the output into a variable with the AutIit StdoutRead() function, but I just can't get the output from an external program such as eac3to.exe - it just desn't seem to work whatever I do!  Just for testing purposesI I don't even need to get the output to a a GUI window: just printing it with ConsoleWrite() is good enough as this proves that I was able to read it into a variable.  So at this stage that's all I need to do - get the text (usally about 10 lines) that has been output to a cmd window by my external CLI program into a variable. Once I can do this the rest will be a lot easier.  This is what I have been trying, but it never works:-
-------------------------------------------------------------------------------------------------------------
#include <MsgBoxConstants.au3>
#include <AutoItConstants.au3>

Global $iPID = Run("C:\VIDEO_EDITING\eac3to\eac3to.exe","", @SW_SHOW)
Global $ScreenOutput = StdoutRead($iPID)
ConsoleWrite($ScreenOutput & @CRLF)
-----------------------------------------------------------------------------------------------------------
After running this script all I get from the consolWrite() is a blank line - not the text data that was output as a result of running eac3to.exe (running eac3to without any arguments just lists a screen of help text relating to all the commandline options), and that's what I am trying to get into a variable so that I can put it to use later in the program.
I am really hoping there are at least some good programers out there who can point me in the right direction before I pull out all of my hair in sheer frustration!

I am attempting to design a front end GUI for a CLI program by the name of eac3to.exe. The problem as I see it is that this program sends all of it's output to a cmd window. This is giving me no end of trouble because I need to get a lot of this output into a GUI window. This sounds easy enough, but I am begining to wonder whether I have found one of AutoIt's limitations?
I can use the Run() function with a windows internal command such as Dir and then get the output into a variable with the AutIit StdoutRead() function, but I just can't get the output from an external program such as eac3to.exe - it just desn't seem to work whatever I do!  Just for testing purposesI I don't even need to get the output to a a GUI window: just printing it with ConsoleWrite() is good enough as this proves that I was able to read it into a variable.  So at this stage that's all I need to do - get the text (usally about 10 lines) that has been output to a cmd window by my external CLI program into a variable. Once I can do this the rest will be a lot easier.  This is what I have been trying, but it never works:-
-------------------------------------------------------------------------------------------------------------
#include <MsgBoxConstants.au3>
#include <AutoItConstants.au3>

Global $iPID = Run("C:\VIDEO_EDITING\eac3to\eac3to.exe","", @SW_SHOW)
Global $ScreenOutput = StdoutRead($iPID)
ConsoleWrite($ScreenOutput & @CRLF)
-----------------------------------------------------------------------------------------------------------
After running this script all I get from the consolWrite() is a blank line - not the text data that was output as a result of running eac3to.exe (running eac3to without any arguments just lists a screen of help text relating to all the commandline options), and that's what I am trying to get into a variable so that I can put it to use later in the program.
I am really hoping there are at least some good programers out there who can point me in the right direction before I pull out all of my hair in sheer frustration! :'(
Many thanks

 

Many thanks

 

Link to comment
Share on other sites

12 hours ago, dandino said:

I can use the Run() function with a windows internal command such as Dir and then get the output into a variable with the AutIit StdoutRead() function,

Can't believe you have the know how to do this. If you realy have this knowledge you can also doit with eac3to.exe, so why not using?

I am missing the correct params for run, specialy the opt_flag. Without using this flag you never ever got the output from Dir into a variable with the AutoIit StdoutRead() function. Just the same with eac3to.exe . I suggest read helpfile about Run and StdOutRead and test also example. After you have the knowledge to get the output from Dir and also eac3to.exe .

Edited by AutoBert
Link to comment
Share on other sites

The help and example (F1) for StdOutRead should help you out.

Local $iPID = Run(@ComSpec & ' /C ...your command...', $sFilePath, @SW_HIDE, $STDOUT_CHILD)

    ; Wait until the process has closed using the PID returned by Run.
    ProcessWaitClose($iPID) ; <--- NB

    ; Read the Stdout stream of the PID returned by Run. This can also be done in a while loop. Look at the example for StderrRead.
    Local $sOutput = StdoutRead($iPID)

 

Edited by aiter
Link to comment
Share on other sites

Hi there AutoBert / aiter / TheDecoder,

Thanks very much for your replys and suggestions.  I have used the help example for the StdoutRead() function and just changed the the details of the Run() function to actualy run My program "eac3to.exe" instead of runing the window Dir command.  Incidentaly I tried the Dir example first, and it did work with the ConsoleWrite() function that I inserted for test purposes.

However when I change the details to my eac3to.exe file (code below) it doesn't work - I get no output from the ConsoleWrite() function ??  In fact I'm not even sure that eac3to.exe actually runs? as I dont see a cmd window flash across the screen - not even for an instant!

I'm still non the wiser - Any further help appreciated

---------------------------------------------------------------- My Code

#include <AutoItConstants.au3>
#include <MsgBoxConstants.au3>
#include <Array.au3> ; Required for _ArrayDisplay only.

Example()

Func Example()

       Local $iPID = Run(@ComSpec & '/ C:\VIDEO_EDITING\eac3to\eac3to.exe', @SW_SHOW, $STDOUT_CHILD)
       ; Wait until the process has closed using the PID returned by Run.
       ProcessWaitClose($iPID)

      ; Read the Stdout stream of the PID returned by Run. This can also be done in a while loop. Look at the example for StderrRead.
      Local $sOutput = StdoutRead($iPID)
      ConsoleWrite($sOutput)

EndFunc   ;==>Example

------------------------------------------------------------------------

Link to comment
Share on other sites

Try this:

#include <AutoItConstants.au3>
#include <MsgBoxConstants.au3>

Example()

Func Example()

    Local $iPID = Run(@ComSpec & '/ C:\VIDEO_EDITING\eac3to\eac3to.exe', @SW_SHOW, $STDERR_CHILD + $STDOUT_CHILD)
    if @error Then Exit MsgBox(16,'eascto','not running')
    Local $sOutput = ""
    While 1
        $sOutput &= StdoutRead($iPID)
        If @error Then ExitLoop
    WEnd
    MsgBox(64, 'StdOut: ', $sOutput)
    $sOutput = ""
    While 1
        $sOutput &= StderrRead($iPID)
        If @error Then ExitLoop
    WEnd
    MsgBox(64, 'StdErr: ', $sOutput)
EndFunc   ;==>Example

 

Link to comment
Share on other sites

17 minutes ago, AutoBert said:

Try this:

#include <AutoItConstants.au3>
#include <MsgBoxConstants.au3>

Example()

Func Example()

    Local $iPID = Run(@ComSpec & '/ C:\VIDEO_EDITING\eac3to\eac3to.exe', @SW_SHOW, $STDERR_CHILD + $STDOUT_CHILD)
    if @error Then Exit MsgBox(16,'eascto','not running')
    Local $sOutput = ""
    While 1
        $sOutput &= StdoutRead($iPID)
        If @error Then ExitLoop
    WEnd
    MsgBox(64, 'StdOut: ', $sOutput)
    $sOutput = ""
    While 1
        $sOutput &= StderrRead($iPID)
        If @error Then ExitLoop
    WEnd
    MsgBox(64, 'StdErr: ', $sOutput)
EndFunc   ;==>Example

 

Thanks AutoBert.  I ran that and It exited on the first test with "Not Running"
Looks like something must be wrong with the Run paramters - what do you think?
 

Link to comment
Share on other sites

I copied from your script, but the parameters are wrong, so change to 

Local $iPID = Run(@ComSpec & '/ C:\VIDEO_EDITING\eac3to\eac3to.exe','', @SW_SHOW, $STDERR_CHILD + $STDOUT_CHILD)

without the empty string for workindir this parameter and all following parameters are wrong. If also exiting try with the folder "C:\VIDEO_EDITING\eac3to" as parameter workindir.

Link to comment
Share on other sites

1 hour ago, dandino said:

TheDecoder

You spelled it wrong! :mad:, Its "TheDcoder" :P.

Anyway, have you downloaded my UDF yet? It contains an example for reading the output of a program, you should study the code! I can help you with anything you don't understand in it :).

EasyCodeIt - A cross-platform AutoIt implementation - Fund the development! (GitHub will double your donations for a limited time)

DcodingTheWeb Forum - Follow for updates and Join for discussion

Link to comment
Share on other sites

8 minutes ago, AutoBert said:

I copied from your script, but the parameters are wrong, so change to 

Local $iPID = Run(@ComSpec & '/ C:\VIDEO_EDITING\eac3to\eac3to.exe','', @SW_SHOW, $STDERR_CHILD + $STDOUT_CHILD)

without the empty string for workindir this parameter and all following parameters are wrong. If also exiting try with the folder "C:\VIDEO_EDITING\eac3to" as parameter workindir.

Thanks again AutoBert. Will give it a try and let you know how I get on.

Link to comment
Share on other sites

4 minutes ago, TheDcoder said:

You spelled it wrong! :mad:, Its "TheDcoder" :P.

Anyway, have you downloaded my UDF yet? It contains an example for reading the output of a program, you should study the code! I can help you with anything you don't understand in it :).

Awww sorry about the name, TheDcoder ! :)  I will d/l your UDF soon, I was just trying to sort it out without any extra functions first.

Link to comment
Share on other sites

AutoBert,
After so many combinations of params. the only way I can get this to run is with the code below.  eac3to.exe does run and I get the output (though a lot of it is gibberish!) but after the output it ends with the message "StdErr".

 

Local $iPID = Run("C:\VIDEO_EDITING\eac3to\eac3to.exe",'', @SW_SHOW, $STDERR_CHILD + $STDOUT_CHILD)

Output??   This should be the standard help screen with all the various commandline switches but not sure what has happened on the left hand side?

 

Output.jpg

Edited by dandino
Link to comment
Share on other sites

52 minutes ago, dandino said:

Awww sorry about the name, TheDcoder ! :)  I will d/l your UDF soon, I was just trying to sort it out without any extra functions first.

Ok :).... btw, its not required to use my functions, just study them and make your code work using it as a reference ;)

EasyCodeIt - A cross-platform AutoIt implementation - Fund the development! (GitHub will double your donations for a limited time)

DcodingTheWeb Forum - Follow for updates and Join for discussion

Link to comment
Share on other sites

1 minute ago, TheDcoder said:

Ok :).... btw, its not required to use my functions, just study them and make your code work using it as a reference ;)

Thanks TheDcoder, you are very kind.  I have made a little progress with my problem, but I  still willL download and study your UDF.  As they are not part of the standard AutoIt libraries, I take it I will need to save them at the end of any script I write If I intend to CALL any of them?  

Link to comment
Share on other sites

8 minutes ago, dandino said:

I take it I will need to save them at the end of any script I write If I intend to CALL any of them?  

You can just #include my .au3 file to call them, open the au3 file separately to see the code :)

EasyCodeIt - A cross-platform AutoIt implementation - Fund the development! (GitHub will double your donations for a limited time)

DcodingTheWeb Forum - Follow for updates and Join for discussion

Link to comment
Share on other sites

Hi again AutoBert,
Thanks for you help so far your diligence has really helped me stay with this problem.  At least now I am able to read in the output text from eac3to.exe.  As it is now working (in a fashion) I have run eac3to.exe from my script with the commandline switch/option to output the various media tracks from a bluRay disk - and again it works, but the output appears to be formated in a strange way!?  (see my attached image of the output)

The output should only consist of text and should be as follows:-

1) 00000.mpls, 00000.m2ts, 1:34:51
    - Chapters, 12 chapters
    - h264/HVC, 1080p24 /1.001 (16:9)
    - DTS Master Audio, English, multi-channel, 48kHz

This is how it appears when run in a CMD window - and must have been read in like that with the StdoutRead() function?  Therfore I'm a little puzzled as to why it has been displayed in this strange format with the MessageBox() function.  I really need to know how to output this listing as above?

Again any help would be very much appreciated.

Output3.jpg

Link to comment
Share on other sites

This is how it comes out:-

---------------------------
StdOut:
---------------------------
1) 00000.mpls, 00000.m2ts, 1:34:51                                             

   - Chapters, 12 chapters                                                     

   - h264/AVC, 1080p24 /1.001 (16:9)                                           

   - DTS Master Audio, English, multi-channel, 48kHz                           


---------------------------
OK   
---------------------------


But when I run it it looks like the image I posted above - the Ctrl+C didn't copy all the (backSpace) charachters that actually appeared in the MessageBox!

Thanks

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...