How to translate execution commands from bash script to C? or How to properly use popen() in "W" mode? -
hey all. i'm trying translate simple bash script executes program (called pdb2gmx) c commands can include function in larger program, i'm having trouble making happen.
the bash script:
#!/bin/sh /usr/local/gromacs/bin/pdb2gmx -f ${1}.pdb -o ${1}.gro -p ${1}.top << eof 14 6
so what's going when running program, stops , asks user input @ 2 separate points, 1 right after other. in bash script, putting down 14 , 6 seems fulfill input requirement, can't seem pull off same trick in c (also, i'm not sure eof doing there, i'm following else's example that, , script won't work without it).
this have far in c:
#include <stdio.h> #include <stdlib.h> int main() { file * pdb2gmx; pdb2gmx = popen( "pdb2gmx -f 1beo.pdb -o 1beo.gro -p 1beo.top" , "w" ); fprintf( pdb2gmx, "eof" ); fprintf( pdb2gmx, "14" ); fprintf( pdb2gmx, "6" ); pclose( pdb2gmx ); }
but when code executed pdb2gmx hangs @ first point needs user input. missing?
my sense c program hanging on execution of popen
line, , never getting fprintf
lines, thought popen
mode set "w"
treat returned stream user input, i'm pretty confused.
you need add newlines (\n
) end of fprintf
strings...
Comments
Post a Comment