Created
June 27, 2019 17:38
-
-
Save segfo/ee99a495b7b11d6b57e7123426e18707 to your computer and use it in GitHub Desktop.
子プロセス起動&子プロセスの標準出力を順次取得
This file contains 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
import time | |
cnt=0 | |
while True: | |
cnt+=1 | |
if cnt > 5: | |
break | |
time.sleep(1) | |
print("python: "+str(cnt)) | |
This file contains 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
use std::process::Command; | |
use std::io::Read; | |
fn main(){ | |
let mut child = Command::new("powershell") | |
.args(&["/C", "./test2.ps1"]) | |
.stdout(std::process::Stdio::piped()) | |
.spawn() | |
.expect("failed to execute process"); | |
let mut buf=vec![0u8;1024]; | |
loop{ | |
let r = child.stdout.as_mut().unwrap().read(&mut buf); | |
if r.is_err(){ | |
break; | |
}else if r.as_ref().unwrap() == &0usize{ | |
break; | |
} | |
print!("{}",String::from_utf8(buf[0..r.unwrap()].to_vec()).unwrap()); | |
} | |
} |
This file contains 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
adb logcat | |
py -3 -u test.py |
This file contains 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
$cnt=0 | |
while(1){ | |
$cnt+=1 | |
if($cnt -gt 5){break;} | |
Start-Sleep -Seconds 1 | |
echo $cnt | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment