I want to write a program Shellcode.c that takes in an input text file that contains bash commands separated by a new line and executes all the commands in a text file: for example, a text file will contain:
echo Hello World mkdir goofy ls
I tried this (just to start practicing with one of the exec functions):
#include <stdio.h> #include <unistd.h> void main() { char *name[3]; name[0] = "echo"; name[1] = "Hello World"; name[2] = NULL; execvp("/bin/sh", name); }
I get in turn
echo: Can't open Hello World
I am stuck in execvp function, where did I go wrong?
c bash execvp
elmazzun
source share