Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 3 years ago.
Improve this question
I want to debug a C program.
./test 1 2 3 << end
Monos(1,2)
Monos(6)
end
How to debug this?
For easier debugging with GDB, you should convert the "here string" lines between the <<end and end into a text file (say "input.txt"). Then, in gdb you can use the set args command to set up the command-line arguments and redirection of standard input from the file.
For example: suppose the file "input.txt" contains:
Monos(1,2)
Monos(6)
Run gdb from the shell as follows:
$ gdb ./test
Within GDB, set the command-line arguments and redirection of standard input:
(gdb) set args 1 2 3 < input.txt
Set any breakpoints, e.g.:
(gdb) b main
And start running the code:
(gdb) r
Don't do this redirection on the gdb command-line, but instead do it on the run command inside gdb.
https://sourceware.org/gdb/current/onlinedocs/gdb/Input_002fOutput.html#Input_002fOutput
Related
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 11 months ago.
Improve this question
I have a C program which reads its input from the command line, I would like to feed the executable with the output of ls | wc -m command, as I need to call two instances of the executable (./a.out1 , ./a.out2) using that same input and make them running in parallel (pipes ?).
Thank you for your help in advance!
You say you want to use a pipe, so first of all you need to adapt your program to read the input from stdin instead of argc and argv. Input passed via a pipe is not added to the command line argument list.
To pipe stdout of a process to multiple other processes, you can use tee and process substitutions:
ls | wc -m | tee >(./a.out1) >(./a.out2) >/dev/null
However, the reason why you require it be piped (as opposed to passed as an argument) isn't clear to me, so storing the output in a variable as suggested in the comments would work just as well for the example you present.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 years ago.
Improve this question
I have Linux Ubuntu, and I want to test my program, for which someone gave me .txt file of multiple inputs. Now I want to run this program with inputs written in the .txt file. Theres a lot of inputs so I dont want to input them by hand. Is there some command in Linux Terminal to run a C with inputs written in a file?
thank you for your answers
I think you are suffering from the all too common misunderstanding that "standard input" == "a keyboard". Stop thinking that. If you've already written a program that reads from stdin, all you need to do is associate your text file with stdin. In the shell, you do that with a redirection operator:
./a.out < input.txt
If you have multiple inputs, you can easily invoke your program on each individually:
for file in *.txt; do
echo "Running on input: $file"
./a.out < "$file"
done
or you can run your program once on all the inputs:
cat *.txt | ./a.out
There are many, many ways to do what you want, and a lot of flexibility to do different things. You'll probably want to compare the output of your program with the expected output and then you're on your way to writing a full-fledged test suite. For example:
if ! ./a.out < input.txt | cmp expected-output -; then
echo "TEST FAILED" >&2
exit 1
fi
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
I have own script in C for linux, it is working with string loaded from file. I compiled on server gcc -pthread -o pipeline pipeline.c. It is working. Now I am running this script any like this ./pipeline UPPERCASE LOWERCASE < my_file.txt. I can read all arguments but I dont know how to read file name behind < in this script. It is possible, or how is it working?
The contents of that file will show up on your process's standard input (stdin). You don't get the name of the file, as the same interface will be used in situations where there's no filename, such as when the output of another process is piped to yours (doSomething | pipeline UPPERCASE LOWERCASE), or when the user's terminal is used for input by default.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
If I want to use one exe file with the command like this:
1.exe < input.txt > output.txt
To enter the file name into the C program which is used to modify the input file and output file, will it work?
I have tried with 1.exe input.txt output.txt it works.
However, when I changed it into 1.exe < input.txt > output.txt, it could not open the file.
Even, I increased the pointer, argv[1] to argv[2] and argv[2] to argv[4].
So, what should I do with 1.exe < input.txt > output.txt command?
When you do this: 1.exe input.txt output.txt, it passes input.txt as the first argument to 1.exe and output.txt as the second argument.
This is different from 1.exe < input.txt > output.txt, which puts the contents of input.txt on stdin and writes stdout to output.txt.
The program 1.exe is expecting to be given the names of files which it then opens and operates on. It does not expect to read from stdin and write to stdout. If that's what you want to do, you need to modify the program to make it do that.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I have a C program that takes in 2 separate inputs through the read(0,buffer,size(buffer)) function.
They take two different inputs. Is it possible, through bash command only, to pipe two pytho -c or perl -e scripts into the C program? Or do I have to change its source code? Thanks in advance
You can use a command group
{
echo "First command"
echo "Second command"
} | nl
Or on one line for your interactive editing convenience:
{ echo "First"; echo "Second"; } | nl