我试图在c中编写一个简单的shell,我开始从网上抓取一些代码进行简单的解析,但是当我尝试用args执行命令时,我遇到了问题,例如ls -l它会忽略参数,system()不会考虑这些参数吗?无论如何,下面的代码
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#define DELIMS " \t\r\n"
#include <errno.h>
#include <string.h>
int main(int argc, char *argv[]) {
char *cmd;
char line[1024];
printf("Starting Omar's Shell\n");
while (1) {
printf("What can i do for you?>");
if (!fgets(line, 1024, stdin)) break;
// Parse and execute command
if (cmd = strtok(line, DELIMS)) {
// Clear errors
errno = 0;
if (strcmp(cmd, "exit") == 0) {
break;
} else {
if(system(line) !=0){
printf("An error has occured\n");
}
}
if (errno) perror("Command failed");
}
}
return 0;
}
答案 0 :(得分:0)
<asp:Panel ID="Panel" runat="server" onClick="yourJsFunction()" width="106px" BorderStyle="Solid" BorderWidth="3px" BackColor="Wheat">
<asp:Image ID="img" runat="server" CssClass="image" /> <br />
<asp:Label ID="name" runat="server" Text="name" Width="100px" CssClass="text" /> <br />
<asp:Label ID="price" runat="server" Text="Label" Width="100px" CssClass="text" /> <br />
</asp:Panel>
打破了原始行。这就是它的工作原理,它插入strtok
,以便您可以遍历令牌。在使用'\0'
之前,请使用不同的方法或复制字符串。 - 凯尔塔尔