0

I'm creating a test script for a program that relies on user input. To start my program from my test file, I use

system("./calc")

This initializes the program as expected. So I tried to do the same with a few inputs.

system("1+1")
system("2+2")
etc...

However, what ends up happening is my program starts, but still waits for explicit user input from me. Its only when I quit out of my program that the subsequent system() calls execute. But of course, since the program ended, they mean nothing at that point.

Its clear that the first system() call waits for the program to finish executing before going to the next lines of the test program. How can I issue commands from a test script while the program is running?

Bob
  • 715
  • 2
  • 11
  • 32
  • @JonnyHenly: It sounds like the OP wants to feed input in pieces from the parent process... – Kerrek SB Nov 20 '16 at 21:34
  • @Kerrek that is correct. Basically I want this test file to input a bunch of commands, then quit so I can view the results – Bob Nov 20 '16 at 21:35
  • 1
    There is no portable way to manage subprocesses in standard C. Different platforms offer different mechanics for this (e.g. fork, exec, epoll in Linux). – Kerrek SB Nov 20 '16 at 21:36
  • Under Linux, this might prove useful: http://stackoverflow.com/questions/9405985/linux-3-0-executing-child-process-with-piped-stdin-stdout. – BizarreCake Nov 20 '16 at 21:40

0 Answers0