Make run passing command line args to executable

Hello,

is there a way that make run can pass command line args to my app.
I quite often write cli tools and the typical flow is:

  • make
  • ./bin/ofApp.app/Contents/MacOS/ofApp -p 8000 -h localhost

i would love to be able to run
make run -p 8000 -p localhost

Any pointers?

Thanks
Thomas

#include “0.h”

#include ofMain

Int,Float Main ( char * chars, int arcgc ) {

#include <stdio.h>
// This could hold the space to Any OF app
int main( int argc, char *argv[] ) {

if( argc == 2 ) {
printf(“The argument supplied is %s\n”, argv[1]);
}
else if( argc > 2 ) {
printf(“Too many arguments supplied.\n”);
}
else {
printf(“One argument expected.\n”);
}

// here you could do something to arguments.
ofApp = new ofApp();
// setup code here
while(1){
// update, draw, sample,…
]

program done, lets exit

}

return 0:0.0;
}

[… ø

sorry for not being clear, i know how to parse the command line args, usually i use cxxopts for that.

I just wanna avoid to type the path to binary if possible.
instead of ./path/to/binary -s -o -m -e options i would love to just run make run -s -o -m -e options

HI.
If you just like to do it in a single line you can do

make && ./bin/ofApp.app/Contents/MacOS/ofApp -p 8000 -h localhost

If you want more freedom to change options, i’d go with a simple shell script:

#!/bin/sh
if [ $# -eq 2 ]; then
  PORT=$1
  HOST=$2
else
  PORT=8000
  HOST=localhost
fi
make
./bin/ofApp.app/Contents/MacOS/ofApp -p $PORT -h $HOST

(shoud work in linux, not tested in macOS)

save as compile_and_run.sh and you’ll be able to do

./compile_and_run.sh 8000 localhost

or simply

./compile_and_run.sh

HTH

1 Like