我在 linux 中有一个 ac 程序,它使用 fwrite 读取 php 发送的数据并在 linux 中输出一个字符串。
AJAX
$.ajax({
type: "POST",
data: {cmd:"IN"},
url: "COMMAND.php",
success: function(data){
//Get only this string ">" from the stdout of linux and store it to a variable.
}
});
命令文件
<?php
if($_POST['cmd']=="IN"){
$fd = fopen("/tmp/myFIFO","w");
fwrite(fd,"IN");
fclose(fd);
}
?>
C
char buf[255];
while((n = read(fd, buf, sizeof buf - 1)) > 0 ){ //fd is the opened pipe.
buf[n - 1] = '\0';
if(strcmp(buf,"IN")==0){
printf("%s\n", "FF0023sff344>fdfslldlf");
}
}
如何从linux捕获字符串“FF0023sff344>fdfslldlf”到ajax并只获取字符串“>”..?