1

I would like to pass an argument to a c++ program in a shell script that just prints it to the console. However, I want to use gnu parallel to do it. At the moment I have a shell script,

#!/bin/sh
parallel -k echo ::: 1 2 3 > cTest
parallel ./hello :::: cTest

where I first create a file 'cTest' that contains the items that will be passed to the executable 'hello'.

At the moment, the above just prints blank spaces. I have tried doing,

parallel echo :::: cTest | ./hello

but this just prints '2' (I am also concerned that the above won't be in parallel).

Does anyone know how to get this working?

2
  • You are doing the right thing, so let us first rule out, that there is anything wrong with your installation. Does gnu.org/software/parallel/parallel_tutorial.html work as expected?
    – Ole Tange
    Commented Dec 3, 2016 at 5:42
  • All works fine -- I ran through the tutorial part by part before I started.
    – ben18785
    Commented Dec 5, 2016 at 2:38

1 Answer 1

1

This works for me:

#!/bin/sh

cat <<EOF >hello.cpp

#include <iostream>

int main(int argc, char** argv) {
  std::cout << "Have " << argc << " arguments:" << std::endl;
  for (int i = 0; i < argc; ++i) {
    std::cout << argv[i] << std::endl;
  }
}

EOF
g++ hello.cpp -o hello

parallel -k echo ::: 1 2 3 > cTest
parallel ./hello :::: cTest

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.