0

For example, Guess I have a compiled c program, named as 'binaryOutput'. And in Unix environment, [root@blablabla ~ ] ./binaryOutput print out some result like this [0] [1] [0] [1] [1]

I want to using these result as the input of another c file.

In C lanugage, I can run the file.

system("./binaryOutput") ;

After the code, I want to add the numbers as an array's input. How can I do it?

3

1 Answer 1

2

popen example. You can get the output of the command.

#include <stdio.h>

int main(void)
{
  FILE *fp=NULL;
  char line[1024];
  if ( (fp=popen("ls", "r"))==NULL )
  {
    return -1;
  }
  while( fgets(line, 1023, fp)!=NULL )
  {
    printf("read from popen:%s", line);
  }
  pclose(fp);
  return 0;
}
Sign up to request clarification or add additional context in comments.

5 Comments

Could you also describe how your code works? It looks like your program collects dir listing. That's not what OP is looking for. The question asks about executing any executables. Not a specific unix command. So tell us the generic approach.
replace "ls" to what you want. "./binaryOutput"
@MohammadRakibAmin ls is part of the set "any executables".
fgets(line, sizeof line, fp) -- there is no reason to reduce the size parameter to fgets by 1 as you do for scanf field-width modifier.
@Michael Walz I was unaware you have to figure out what 'set' does an input belongs to, then check if that 'set' covers your desired input. Would it not be more helpful to just mention your command goes here? I'm only pointing out ways to be more clear to OP's query.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.