I'm not sure why you pass this through /bin/sh ... but since you are there, you need to pass all the arguments after -c as a single value, because now they should be interpreted using /bin/sh .
An example is shell syntax comparison.
/bin/sh -c ls -a
to
/bin/sh -c 'ls -a'
The second works, but the first does not.
So your ptr should be defined as
char * const ptr[]={"/bin/sh","-c","ls -a" ,NULL};
source share