Created
September 21, 2017 14:06
-
-
Save lleqsnoom/96fd20ecdfced904318043a794426b76 to your computer and use it in GitHub Desktop.
haxe linux/mac shell commands with pipes
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package; | |
import sys.io.Process; | |
using StringTools; | |
class Shell | |
{ | |
public static function main() { | |
trace(exec('ioreg -c IOSerialBSDClient | grep usbmodem | grep IODialinDevice | cut -d " -f 4')); | |
} | |
public static function exec(command:String):String{ | |
var cmdArr = command.split("|"); | |
var tp:Process = null; | |
var p:Process = null; | |
for(cmd in cmdArr){ | |
var arr:Array<String> = cmd.ltrim().rtrim().split(" "); | |
p = new Process(arr.shift(), [].concat(arr)); | |
if(tp != null){ | |
p.stdin.writeInput(tp.stdout); | |
p.stdin.close(); | |
tp.close(); | |
tp.exitCode(); | |
} | |
tp = p; | |
} | |
var s = p.stdout.readAll().toString(); | |
p.close(); | |
p.exitCode(); | |
return s; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment