Actually I have trouble naming the title of this post. Because I don't know how to summarize my meaning in a professional way. But I'll explain my question as below:
I'm running a program written by C++, command is:
./VariationHunter_SC
Then it'll let you type in many parameters:
Please enter the minimum paired-end insert size:
Please enter the maximum paired-end insert size:
Please enter the pre-processing mapping prune probability:
Please enter the name of the input file:
Please enter the minimum support for a cluster:
Obviously I need to type in such parameters one by one to run the program; But I have thousands of such jobs, and need to pre-assign such parameters in script, and submit script to computer.
So how can I do that?
thx
Edit
so how can I make parameter-list?
Just like below?:
140
160
0
mrfast.vh
1
Seems the program cannot recognize these numbers, and distribute numbers..
This depends on how the program actually reads the data that you type in - it's likely that its reading stdin, so you could use separate files with the parameters and pass them in via redirection: ./VariationHunter_SC < parameter-file
It's also possible that the program will accept parameters on the command line, but there's no way of really knowing that (or how) except by whatever documentation the program might come with (or by reading the source code, if it's available and there is no other accurate docs).
Simply use the piping character to pipe the contents of a file to your program
example, in a windows command shell:
echo "asdf" | pause
This will pass "asdf" to the pause program. As a result, pause will print a "Press any key to continue" message, then imediately continue because it will receive the "asdf" string as a response.
So, overall, write or use a program that outputs the contents of your file. Call it, then pipe its output to the program that needs the input.
The unix cat command is such a command that writes the contents of a file to output, or to the input of another executable if you are piping the output.
Related
I am very new to C++. I have my code and it displays my desired output in a win32 console.
However, my Instructor wants the output to be run through a .txt file. We have done this before with a program that had input already written within the coding.
ex.
cout << "example1....example2";
We achieved this with his exact instructions:
*1) Probably the easiest way to obtain a hard copy of the generated
program output on a Microsoft Windows platform is to run your
program from a command prompt, redirecting the output to a file.
The command line syntax would like like this:
lab1prog >lab1.txt*
My problem, however, is that I did this again for lab2 and redirected the output to lab2.txt but I need user input for this time around. When I run the lab2.exe file, my lab2.txt file outputs my "cout" statement and waits for input but I cannot enter input through a .txt file.
Please help if you can.
When you redirect the output of the program with
lab1prog >lab1.txt
then the user is still able to input data. The only problem is that she doesn't know when to enter what data. This is usually done by prompt outputs that are hidden whith the >lab1.txt.
To circumvent the problem you could abuse the error output what is not redirected with the command above.
cerr << "prompt";
To avoid this abuse you should use a "tee" program like wintee instead of redirecting with a simple >lab1.txt.
If it's acceptable to get the input from a file instead from the user you can use the input redirection.
labprog1 <input.txt >lab1.txt
If you specifically want to use a text file as input into your program, the easiest way (as Kamil Mikolajczyk mentioned) is to run it this way:
> lab1prog >lab1.txt <input.txt
On the other hand, if you need to run the program as it is, but have complete control over what to output into the file, I'd suggest using a file handle. Check out this question on how to use file handles. You could even duplicate the output on the command prompt and the file when you want by outputting it as:
fout << "My output";
cout << "My output";
You can as well output the user input into your output file for your convenience.
I have a program I am writing, I have already completed it, but the requirement/specification for it says that:
In the "Command Prompt", if someone runs your program like this:
Peter David < savednames.txt
it should print out the names inside savednames.txt that matches each of "Peter" and "David"
I have written the program but my own is interactive, i.e it asks for the file, then the name you want to search for, and then it prints the matches.
It works perfectly fine, but I don't understand what the running of the program in command prompt like this: "Peter David < savednames.txt" means. I am using C++ on Microsoft Windows.
Please I need your help to explain it and how to implement it in my code...is it some kind of operator overloading or ...I don't understand!
On the command line, < is used for input redirection. The shell opens the file whose name follows the < and copies its contents into standard input for the program.
So if you called program input.txt, you could open the file and read its contents using std::ifstream or whatever; if you called program < input.txt, you could just read the file's contents from stdin using cin.
You can also do the same for output. Instead of opening a file and writing to it in your code, write to stdout and call your program as program > output.txt.
yourprogramname Peter David < savednames.txt
means that your program will be called with Peter as first argument, David as second argument, and its standard input will be connected to a stream reading out of savednames.txt.
You just need to read standard input one row at a time, and process it according to the arguments you received.
You just need to modify the code you already have to take the names from the command line (is there a limit? Could there be three names? Or four? You need to consider that) and to read the data from standard input stream, without any need of opening a file.
I have a two C++ source code in which one code generates an array for the specified input while other has to use array for execution. I want to know how can I link two C++ file such that output of the first file is the input for second one ?
Since they're separate programs, that means they each have a main() function. Because of that you can't link them together. What you can do, however, is use the shell to redirect the output from one program to the input of another. For example:
program1 | program2
The above creates a so-called "pipe". What it does is feed program2 with the output of program1. Only the standard input and standard output are redirected that way. In C++ that means std::cin and std::cout. Anything printed on std::cerr or std::clog is not redirected, so make sure to never print errors, warnings or other status/informational messages on std::cout. Only print the payload data and use std::cerr or std::clog for anything else.
Linux: Compile both files and push the content of the first to the second binary with a pipe in terminal else use a socket.. you can try to ouput the data with a binary-stream and the second binary can use the same techniqe to pushs it into a array.. i hope that helps you..
How can I save all the input(cin) and output(cout, cerr) from a program whose input is taken from file(using "<")? I would like the input and output to be in order(so each input is followed by corresponding output as if I were typing the input in myself).
I tried ">" to output everything to a file, but that only saves standard output(no input/cerr), and just plainly copying the command line output still only gives the output without the input(because of how "<" works).
Is there a way to write everything(output+input) to file in order?
EDIT: edited for clarity
EDIT2: I just realized that it's impossible to do what I'm trying to do since the console does not know anything about when the commands would actually be entered. I'll have to manually enter commands and use the "script" command to actually log all input/output.
You need to add cerr to the stream
command > file 2&>1
This means put 2 (stderr) to 1 (stdout) as well.
I need to control a program in c++ (windows), I need to call it, then pass data to it as I collect it, finally after a certain command that program will use that data.
I need to open the prog.exe and then line by line or value by value supply it information, it works manually through cmd.
I have tried system() but this will stop after I open the program.
I need something like this.
//call it
prog.exe
//add data
DataStart
Data 1 [2 34 454 5]//etc
DataEnd //the program will take it from here.
all being passed though command line
There are different ways you could do this - if your program needs to execute part of the way through your code before getting the data as input, you can just use standard input, and prompt the user to type the data. If you want to use variable values for the input, but you will know them before execution, you can pass the information as command line arguments, where you will execute like so
prog.exe 1 2 3
and your program will access the data via argv[i] where i corresponds to each command line argument.
have your program read from standard input, and from the command line 'pipe' the result of the other program to yours
eg.
datagenerator.exe | prog.exe
assuming that datagenerator.exe writes to standard output, the | character will redirect the output to prog.exe's standard input