我真的把我的头发拉出来了。我正在尝试为我的 IRC 机器人创建远程 shell 执行,但是,当我使用诸如 "ls" 或 "cd" 之类的命令时,我得到了 ": not found" 的返回,但是,其他命令,例如 mkdir 或回声似乎工作正常。当我对命令进行硬编码时也是如此,我得到的输出与它应该的完全一样。
谁能明白为什么?这是我的代码:
            FILE *fp;
            int status;
            char path[1035];
            /* Open the command for reading. */
            fp = popen(ptr1, "r"); // hard code command and it works ????fp = popen("/bin/ls /etc/", "r");
            printf("%s", ptr1);//check received command (debugging)
            if (fp == NULL) {
                printf("Failed to run command\n" );
出于道德原因删除了一些代码。