Skip to content

Instantly share code, notes, and snippets.

@segfo
Created June 27, 2019 17:38
Show Gist options
  • Save segfo/ee99a495b7b11d6b57e7123426e18707 to your computer and use it in GitHub Desktop.
Save segfo/ee99a495b7b11d6b57e7123426e18707 to your computer and use it in GitHub Desktop.
子プロセス起動&子プロセスの標準出力を順次取得
import time
cnt=0
while True:
cnt+=1
if cnt > 5:
break
time.sleep(1)
print("python: "+str(cnt))
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());
}
}
adb logcat
py -3 -u test.py
$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