#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
int main() {
printf("Transactional Shell Command Test.\n");
while(1) {
printf("Queue:");
char input[500];
fgets (input, 500, stdin);
if(strstr(input, "qb-write")){
printf("These are the commands you have queued:\n");
FILE *cmd = popen("cat /home/$USER/.queueBASH_transactions", "r");
char buf[256];
while (fgets(buf, sizeof(buf), cmd) != 0) {
printf("%s\n",buf);
}
pclose(cmd);
}
system(strncat("echo ",strncat(input," >> /home/$USER/.qb_transactions",500),500));
usleep(20000);
}
return 0;
}
我正在嘗試爲事務性shell創建一個概念,並且我將它輸出到用戶主目錄中的文件中的每個命令。它並沒有完全完成,但我一次只做一個部分。當我輸入「shell」的任何輸入時,它會崩潰。 Codeblocks告訴我「進程返回-1(0xFFFFFFFF)」,然後通常有關運行時的信息。我在這裏做錯了什麼?程序返回-1(0xFFFFFFFF)
不代碼塊沒有一個集成的調試? –
如何呈現特定的程序輸入與崩潰可以複製? –
還請注意,您對'strncat()'的特殊用法不能防止緩衝區溢出,您可能認爲它有此功能。 –