On 2018-01-20, Jordon <open...@sirjorj.com> wrote: > I am still learning cgi/web stuff and stumbled upon an issue. I am > trying to popen() a program to catch what it dumps to stdout. To start > simply, I am just trying to run uname. I get nothing. No errors on > popen() or pclose(), but nothing printed. I run the same code from a > regular cpp program (changing the khtml_puts() to printf() and it works > perfectly. That makes me wonder if there is something environmental > that I am missing, or maybe this is just not allowed. > > My code is this: > > char dump[1024]; > memset(dump, 0, sizeof(dump)); > FILE *f = popen("uname -a", "r"); > if(f == NULL) { > khtml_puts(&r, "popen()FAILED!"); > } else { > khtml_puts(&r, "output: "); > while (fgets(dump, sizeof(dump), f) != NULL) { > khtml_puts(&r, "GOTSOMETHING!"); > khtml_puts(&r, dump); > } > int status = pclose(f); > if(status==-1) { > khtml_puts(&r, "pclose()FAILED"); > } > } > khtml_puts(&r, "done"); > > > All I get from it is "output: done" > > > > Also, my httpd.conf is this: > > ext_addr="egress" > prefork 2 > server "localhost" { > listen on $ext_addr port 80 > root "/htdocs" > location "/cgi-bin/*" { > fastcgi > root "/" > } > } > > Any ideas? > >
popen() requires a shell. You are most likely running it in a chroot and don't have /bin/sh.