1. Get the complete output of a program/command
- Posted by TheDcoder Dec 02, 2017
- 1214 views
Hello, I have been playing around with Euphoria recently :)
I want to get the (standard) output of a program or a command. I know that I can do this using `exec` and `read` but I am not sure how I can wait until the process ends... so really my question is "how to wait until a process ends" but I thought about the big picture and wanted to have a reference where I could go and look.
Can anyone help me out? Thanks in advance!
2. Re: Get the complete output of a program/command
- Posted by irv Dec 02, 2017
- 1200 views
Perhaps http://openeuphoria.org/docs/std_os.html#_1850_system_exec ?
3. Re: Get the complete output of a program/command
- Posted by jmduro Dec 02, 2017
- 1206 views
One other way is to use named pipes. Eu3 Standard Lirary and Eu4 Standard Library on RDS site contain a function named exec_command that shows how to do this.
Jean-Marc
4. Re: Get the complete output of a program/command
- Posted by TheDcoder Dec 02, 2017
- 1169 views
@irv I am not sure how system_exec would be helpful, it only returns the exit code...
@jmduro Thanks for the recommendation, I have seen quite a few of your contributions at the RDS archive, I will check your library/package out :)
5. Re: Get the complete output of a program/command
- Posted by irv Dec 02, 2017
- 1174 views
... but I am not sure how I can wait until the process ends... so really my question is "how to wait until a process ends" ...
system_exec() returns an error code - therefore it must wait until the process it calls ends.
And, since the process is finished, you can just dump the output to a file, and use it:
include std/io.e include std/console.e system_exec("ls -la > lsoutput") object results = read_file("lsoutput",TEXT_MODE) display(results)
6. Re: Get the complete output of a program/command
- Posted by TheDcoder Dec 05, 2017
- 1108 views
@irv I have thought about doing that but I do not want to... for a few reasons: 1. It invokes the shell, adds overhead. 2. Writes the output to disk, which can add a lot of overhead if the data to read is huge 3. The script will have to read all the data back, bad for hard disk
@jmduro I downloaded Eu3 Standard Library and found the exec_command function, but I quickly realized that I need to use the Eu4 Library as I was using Euphoria 4.x, but I did not find the exec_command function there... am I supposed to use the Eu3 Standard Library with Euphoria 4.x?
Thanks for the input guys :)