-1

I have to call one prog1.exe program and give arguments to it and give it's output to another executable prog2.exe in a bash script

prog1 "arguments" | prog2
echo finished

How can I make this to work? Also I suppose echo command won't be executed before prog2 will finish it's work?

EDIT : When I run

prog1 "argument"
prog2 "example"
prog1 "argument" | prog2

I got correct output from prog1 - std::cout << "arguments" << std::endl and it's displayed nicely in console and also prog2 is creating file example.txt so individually both programs are working. Just puting them together with prog1 "arguments" | prog2 doesn't do the trick

etrusks
  • 165
  • 1
  • 8

1 Answers1

1

This really isn't a bash question. This is a C++ question really. prog2 should be reading from stdin as jordanm suggested in the comments. Something like this will read from stdin line by line:

for (std::string line; std::getline(std::cin, line);) {
        std::cout << line << std::endl;
}

Change the cout to do whatever you want with it on each line.

Jason
  • 2,493
  • 2
  • 27
  • 27