In Haxe, is there a method in the Sys class (or some other class) that returns the output of a shell command (for example, the command "ls"), or will I need to implement this method myself for each target language? I'd like to find a method for invoking shell commands that works with every Haxe target language.
-
It would be possible to implement this method separately in each target language (using conditional compilation), but it would be better if this functionality was available in Haxe's standard API. Is it part of the Haxe standard API? – Anderson Green Nov 3 '12 at 21:32
-
1After a lot of searching, I found this relevant thread (which appears to contain the answer to my question!): haxe.org/forum/thread/3395#nabble-td5537667 – Anderson Green Nov 3 '12 at 21:42
Yes, your own comment contain the answer, which is:
var output = new sys.io.Process("ls", []).stdout.readAll().toString();
-
Will I need to import any additional modules to get this to work? – Anderson Green Nov 19 '12 at 4:16
-
Or the cross platform way: sys.FileSystem.readDirectory('')
It might also be faster, because it doesn't invoke an extra process.
-
This is a useful answer, but I think it should be posted as an answer to a separate question (since it is relevant to one specific use case - getting the output of
ls). – Anderson Green Nov 4 '12 at 19:55 -
Also, can you explain why the other way of doing it isn't cross-platform? (Does
var output = new sys.io.Process("ls", []).stdout.readAll().toString();produce different results, depending on the operating system?) – Anderson Green Nov 4 '12 at 19:58 -
Also, is it possible to detect the operating system in Haxe (in a cross-language way?) – Anderson Green Nov 4 '12 at 20:03
-
1
-
1@AndersonGreen
lswill not work on microsoft plattforms afaik, alsolswas given as an example. – NobbZ Jun 5 '13 at 14:41