[omake] How to capture both stdout and return code of shell command?

rudi.grinberg at gmail.com rudi.grinberg at gmail.com
Tue Mar 8 05:21:28 GMT 2016


Thanks Gerd, I will do that for now. Creating a temporary file with omake’s tmpfile seems easy enough so I will do that.


On March 7, 2016 at 1:13:16 PM, Gerd Stolpmann (info at gerd-stolpmann.de) wrote:

There is nothing at hand. Just read a little bit through the source  
code:  

If you call $(shell) or $(shella), this goes straightly to  
Omake_rule.eval_shell_output, which is calling eval_shell_exp. If the  
exit code is not zero, an exception is raised. However, the exception is  
just a generic one, and does not include the exit code in a way you can  
use from omake code.  

If you call $(shell-code) the exception from eval_shell_exp is  
suppressed, and the code is returned.  

Another observation is that eval_shell_output simply creates a temporary  
file and saves the command output there. There seems to be no way to  
directly read into a buffer.  

So, I'd say the way to go (for the time being) is to create a temp file  
and redirect into this while using $(shell-code) to run the whole thing.  

Gerd  


Am Samstag, den 05.03.2016, 19:22 -0500 schrieb rudi.grinberg at gmail.com:  
> Hello,  
>  
>  
> I’ve made good use of shell-code to execute commands and capture their  
> return code but now I’d like to capture their stdout (and stderr if  
> possible) as well, rather than have it dumped on the screen.  
>  
>  
> Is there a simple way to accomplish this? I’ve RTFM’d but could only  
> think of convoluted ways that involve file redirection. I’m probably  
> missing something simple.  
>  
>  
> Thanks,  
>  
>  
> Rudi.  
>  
>  
> _______________________________________________  
> Omake mailing list  
> Omake at lists.ocaml.org  
> http://lists.ocaml.org/listinfo/omake  

--  
------------------------------------------------------------  
Gerd Stolpmann, Darmstadt, Germany gerd at gerd-stolpmann.de  
My OCaml site: http://www.camlcity.org  
Contact details: http://www.camlcity.org/contact.html  
Company homepage: http://www.gerd-stolpmann.de  
------------------------------------------------------------  

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.ocaml.org/pipermail/omake/attachments/20160308/b0a42f45/attachment.html>


More information about the Omake mailing list