非常直接的我想做的事情:
0
,则意味着他们没有输入数字,它应该告诉你.7
,它应该说你做对了.但无论输入是什么,它只输出"7是正确的"线,我无法弄清楚出了什么问题.
<script type="text/javascript">
function problem2 ()
{
var number = 0;
var text=document.getElementById("output");
number = prompt("Enter a number between 1 and 10 please" , 0);
if (number = 0)
{
text.value = "You didn't enter a number!";
}
if (number = 7)
{
text.value = "7 is correct!";
}
else
{
text.value = "Sorry, ", input, "is not correct!";
}
}
</script>
<input type="button" value="Click here" onclick="problem2()">
<input id="output" type="text">
Run Code Online (Sandbox Code Playgroud) 我正在制作一个程序,最终能够(理论上)为传递给它的任何shell命令工作.我的问题是运行的exec不会将其输出放入管道,而是在运行时看起来好像初始调用是进入管道而已?我试过先冲洗stdout但它不起作用.任何帮助表示赞赏!
int main(int argc, char *argv[]) {
int i=0, pid;
int dataPipe[2];
pipe(dataPipe);
char *newArgs[5] = {"/bin/sh", "-c", "ls", "-a", NULL};
if ((pid = fork()) < 0) {
printf("Error: could not fork!");
exit(2);
}
else if (pid == 0) {
close(dataPipe[0]);
fflush(stdout);
dup2(dataPipe[1], 1);
close(dataPipe[1]);
if (execvp(newArgs[0], newArgs) < 0) {
printf("Command Failed to exucute!");
exit(3);
}
}
else {
char buf[BUFFER];
close(dataPipe[1]);
wait(0);
printf("Command exexuted correctly!\n");
while(read(dataPipe[0], buf, BUFFER) != 0) {
printf("Here is the command's output:\n%s\n", buf);
} …
Run Code Online (Sandbox Code Playgroud)