Browse Source

Testing psbasemap with opening /dev/fd

test1
Michael Uleysky 9 years ago
parent
commit
c62fccd415
  1. 23
      test/gmttest.cpp

23
test/gmttest.cpp

@ -9,7 +9,15 @@ int print_func(FILE* fd, const char* str)
std::cout<<"PRINT: "<<str<<std::endl;
return 0;
}
/*
int callgmtmodule(void *API, const char *module, int mode, void *args, std::string& res)
{
int pipefd[2];
int savefd;
}
*/
int main()
{
@ -28,24 +36,28 @@ int main()
gmtapi=GMT_Create_Session(text,2,0,print_func);
//io=GMT_Register_IO(gmtapi,GMT_IS_TEXTSET,GMT_IS_DUPLICATE,GMT_IS_NONE,GMT_OUT,0,0);
//GMT_Encode_ID(gmtapi,fname,io);
pipe(pipefd);
args+=" ->/dev/fd/"+std::to_string(pipefd[1]);
opts=GMT_Create_Options(gmtapi,0,(void*)args.c_str());
//ret=GMT_Init_IO(gmtapi,GMT_IS_TEXTSET,GMT_IS_NONE,GMT_OUT,5,0,opts);
std::cout<<io<<" "<<GMT_NOTSET<<" "<<fname<<" "<<ret<<std::endl;
pipe(pipefd);
pid=fork();
if(0==pid)
{
dup2(pipefd[1],1);
//dup2(pipefd[1],1);
GMT_Call_Module(gmtapi,"psbasemap",GMT_MODULE_OPT,opts);
close(pipefd[1]);
exit(0);
}
else
{
ssize_t br;
std::string s="CALL\n";
// std::string s="CALL\n";
// write(1,s.c_str(),s.length());
close(pipefd[1]);
// close(pipefd[1]);
do
{
br=read(pipefd[0],buffer,4096);
@ -53,7 +65,8 @@ int main()
out.append(buffer,br);
} while(0!=br);
wait(0);
close(pipefd[0]);
// close(pipefd[0]);
}
out.shrink_to_fit();

Loading…
Cancel
Save