0

This is what I have"

#!/bin/bash
MAX=3

for((ctr = 0;ctr < MAX; ++ctr))
do
    ./make.o  > out$ctr.txt
    output$ctr.txt 
done

so I want to take put the output of make.o into out$ctr.txt and in my make.o I call cin, could I take output$ctr.txt as input? I would rather not use input redirection since I would have to rewrite the program.

EDIT: I do not want to use < because then it will give me the contents of the file output$ctr.txt, I do want the actual name of the file not the contents

3 Answers 3

1

Do you mean like this

./make.o < output$ctr.txt  > out$ctr.txt

Edit: if you want the name, then just do this:

./make.o output$ctr.txt  > out$ctr.txt

or maybe this, to echo the name so it can be read from C++ cin:

echo output$ctr.txt | ./make.o  > out$ctr.txt
Sign up to request clarification or add additional context in comments.

2 Comments

I do not want to use input redirection because I do not want to get the context for output$ctr.txt I just want the actual name output$ctr.txt
Edited answer, is either of new versions what you want, then?
0

But what you actually want is:

./make.o output$ctr.txt >out$ctr.txt

where output$ctr.txt is a command-line argument to your program.

Assuming a C++ program, since you mention cin, you handle command-line arguments like this:

int main(int argc, char *argv[])
{
    if (argc < 2) {
        // argv[0] usually contains the program name
        std::cerr << "missing argument\n"
                  << "Syntax: " << argv[0] << " input-file\n";
        return -1;
    }

    char *input = argv[1]; // = "output$ctr.txt"
    // ...
}

First Guess

It sounds like you just want;

./make.o  >out$ctr.txt <output$ctr.txt

> redirects the file descriptor STDOUT_FILENO which is associated with FILE *stdout and std::cout.

< redirects the file descriptor STDIN_FILENO which is associated with FILE *stdin and std::cin.

1 Comment

No I do not want to use < because I do not want to read in the file I simply want to get the name of the file.
0

Just a comment about you loop, another more simpler way to write it is

#!/bin/bash

for i in {0..2}
do
    echo $i
done

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.