2

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
  • 1
    After 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
5

Yes, your own comment contain the answer, which is:

var output = new sys.io.Process("ls", []).stdout.readAll().toString();
|improve this answer|||||
  • Will I need to import any additional modules to get this to work? – Anderson Green Nov 19 '12 at 4:16
  • No. Just note that sys.io.Process is only available on sys platforms. – Andy Li Nov 19 '12 at 16:54
3

Or the cross platform way: sys.FileSystem.readDirectory('')

It might also be faster, because it doesn't invoke an extra process.

|improve this answer|||||
  • 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
    @AndersonGreen: Sys.systemName() will give you the OS name. – back2dos Nov 4 '12 at 22:43
  • 1
    @AndersonGreen ls will not work on microsoft plattforms afaik, also ls was given as an example. – NobbZ Jun 5 '13 at 14:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.