Community
cancel
Showing results for 
Search instead for 
Did you mean: 
jlats2
Novice
123 Views

Running binary file in Linux "with inputs"

Hello,

 

So I am new to linux and binary files so please bare with me and feel free to correct me for my horrid use of terminology.

So I have a main.c file which I am able to make into a binary file and execute it on linux command line (i.e. chmod 777 my_binary and then ./my_binary).

 

1) Is it possible for me to provide an input to my binary similar to a function call. For example could I call: ./my_binary -Input1 -Input2 -Input3 where the inputs (Input1, Input2 and Input3) to my program (what is this process called)?

 

2) Do you know of any tutorials going over this? Or would you be kind enough to provide a demonstration?

 

3) What would I need to do to my main.c file in order to properly receive these inputs (I am imagining that this would be similar to a C function, right)?

 

Thank you for your help.

0 Kudos
1 Reply
93 Views

Hi

You can use the argv and argc as arguments to your main function then achieve the expected behavior.

Please see the external link below for some step by step example.

https://www.thegeekstuff.com/2013/01/c-argc-argv/

Thanks and Regards

Anil

 

Reply