i trying run
echo "hello world" > foo.txt
using execvp.
so far, have this:
#include <unistd.h> int main(void) { char *execargs[] = { "echo", "hello, world! > foo.txt", null }; execvp("echo", execargs); return 0; }
which print out line "hello, world! > foo.txt", instead of creating file named foo.txt text "hello, world!" inside.
someone similar on stack overflow, this:
execlp( "/bin/sh", "/bin/sh", "-c", "cat file1.txt > redirected.txt", (char *)null );
but when changed to
execlp( "echo", "echo", "echo hello world > redirected.txt", (char *)null );
nothing happens.
edit:
doing worked (thanks, sometimesright!)
execlp( "/bin/sh", "/bin/sh", "-c", "echo hello, world! > redirected.txt", (char *)null );
execlp runs executable expects find in path. echo not executable, command runs in context of shell command interpreter such sh or bash.
i take back: in linux there echo executable in /bin. pipe stdout using '>' need assistance of shell 'sh'.
Comments
Post a Comment