Ich versuche, ein Programm zu schreiben, das 2 Dateien vergleicht und zurückgibt, wenn sie gleich sind oder nicht.bash: ./comp.out: Berechtigung verweigert
Ich kann nur die Funktionen zur Verfügung: fork
, dup
, dup2
, open
, write
, exec
und read
.
Wenn ich das Programm unter Linux gcc kompilieren, gibt es:
bash: ./comp.out: Erlaubnis verweigert
der Code:
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
int CheckSimilar(char *path1, char *path2);
int main(int argc, char **argv) {
int returnValue = CheckSimilar(argv[1], argv[2]);
switch (returnValue){
case 1:
write(1, "1\n", 3);
break;
case 2:
write(1, "2\n", 3);
break;
case 3:
write(1, "3\n", 3);
break;
default:
break;
}
return 0;
}
/*
* This function checks if the files are similar or similar by case sensitive
* it gets 2 files, and returns: 3 if identical, 2 if identical but only if not
* case sensitive or 1 else.
*/
Wie kann Ich ändere die Berechtigungen?
[email protected] ~/workspace/targ1OS $ gcc -c ec11.c -o comp.out
[email protected] ~/workspace/targ1OS $ ls
comp.out Debug ec11.c
[email protected] ~/workspace/targ1OS $ ./comp.out /home/shay/Downloads/input.txt /home/shay/Downloads/input.txt
bash: ./comp.out: Permission denied
[email protected] ~/workspace/targ1OS $ comp.out /home/shay/Downloads/input.txt /home/shay/Downloads/input.txt
comp.out: command not found
[email protected] ~/workspace/targ1OS $ ./comp.out /home/shay/Downloads/input.txt /home/shay/Downloads/input.txt
bash: ./comp.out: Permission denied
[email protected] ~/workspace/targ1OS $ ^C
[email protected] ~/workspace/targ1OS $ ls -al ./comp.out
-rw-r--r-- 1 shay shay 2640 Mar 30 10:05 ./comp.out
[email protected] ~/workspace/targ1OS $ chmod ogu+x ./comp.out
[email protected] ~/workspace/targ1OS $ ./comp.out /home/shay/Downloads/input.txt /home/shay/Downloads/input.txt
bash: ./comp.out: cannot execute binary file: Exec format error
[email protected] ~/workspace/targ1OS $ gcc -c ec11.c -o comp.out
[email protected] ~/workspace/targ1OS $ ./comp.out /home/shay/Downloads/input.txt /home/shay/Downloads/input.txt
bash: ./comp.out: Permission denied
[email protected] ~/workspace/targ1OS $ chmod ogu+x ./comp.out
[email protected] ~/workspace/targ1OS $ ./comp.out /home/shay/Downloads/input.txt /home/shay/Downloads/input.txt
bash: ./comp.out: cannot execute binary file: Exec format error
[email protected] ~/workspace/targ1OS $ comp.out /home/shay/Downloads/input.txt /home/shay/Downloads/input.txt
comp.out: command not found
Führen Sie 'sudo./Comp.out', vielleicht? –
Aber ich kann keine Befehle auf dem Terminal verwenden. –
Was meinst du? Darf man sie aus irgendeinem Grund nicht benutzen? –