For Example, I have compiled a C++ program through Cygwin g++ on my Windows PC. It accepts (cin) two strings and parses it to return a single string.
I am thinking of using it in a batch file. Is there any way I can return the result to the .bat program directly by passing the two strings as arguments without actually executing all the input dialogues. (Something like "asd.exe -param1,param2" )
Is it to be implemented in the cpp code end. If so, give me a start where to look upon.
            Asked
            
        
        
            Active
            
        
            Viewed 794 times
        
    1
            
            
         
    
    
        David Yaw
        
- 27,383
- 4
- 60
- 93
- 
                    1Are looking for [argc, argv](http://stackoverflow.com/questions/3024197/what-does-int-argc-char-argv-mean)? – François Andrieux Feb 01 '17 at 19:12
- 
                    Look for command line arguments (see this http://www.cprogramming.com/tutorial/lesson14.html) – Traveling Tech Guy Feb 01 '17 at 19:13
- 
                    If I understand your question correctly, you can use input redirection. – Greg Kikola Feb 01 '17 at 19:13
- 
                    For clarification: You want to take an application that requires user input and make it 'headless' where the required input comes instead from a file that spoofs entering the data so that the application 'thinks' the data was typed in. Correct? – Mikel F Feb 01 '17 at 19:20
- 
                    @MikelF Yep, I just need the result of the program returned or to assign to a variable – Feb 01 '17 at 19:43
- 
                    "return the result to a .bat program" This is actually hard. What do you want to do with this out put? An alternative may be very easy such as program2 < program1 < argsfile – user4581301 Feb 01 '17 at 19:45
- 
                    May be helpful: https://blogs.msdn.microsoft.com/oldnewthing/20120731-00/?p=7003 – user4581301 Feb 01 '17 at 19:49
- 
                    @user4581301 either `echo` it or assign to a variable `set \p =` – Feb 01 '17 at 19:49
- 
                    OK. You have that end then. For the other end I'd just pipe in a file containing the input arguments. `asd < argsfile` where `argsfile` contains `param1 param2` – user4581301 Feb 01 '17 at 19:55
1 Answers
0
            To write to stdin u redirect the stdin using
so
prog<"params"
will execute prog and readin String "params" from std::cin same as redirecting stdout to file.
The other option would be to put the input parameters as arguments to main
main(argv,argc){
and read argc as the array of string arguments to the program
 
    
    
        Comfort Chauke
        
- 126
- 1
- 9