Re: [CentOS] [OT] bash here documents

2013-06-25 Thread Tony Mountifield
In article <20130624172106.61M6U.130379.root@cdptpa-web19-z02>,
Steve  wrote:
> 
>  Tony Mountifield  wrote: 
> > In article <20130624135817.10QZO.129278.root@cdptpa-web19-z02>,
> > Steve  wrote:
> > > Suppose I have this C++ program:
> > > #include 
> > > int main (int argc, char** argv)
> > > {
> > > while (1)
> > > {
> > > char cmd[80];
> > > std::cin.getline(cmd, 80);
> > > std::cout << "response to " << cmd << std::endl;
> > > }
> > > }
> > > 
> > > compiled by: c++ -o junk junk.cpp
> > > 
> > > and I have this bash script:
> > > #!/bin/bash
> > > ./junk < > > blah
> > > bleh
> > > \cC
> > > EOF
> > > echo "Something else"
> > > 
> > > When I run the script, the program starts and waits for input forever.
> > > I have 2 questions:
> > > 1) The "blah" and "bleh" line are not echoed to cout. Why not? Does the 
> > > here document not send the data to stdin?
> > > 2) How do I terminate the program? When run interactively, I use 
> > > -C. 
> > 
> > You should be testing the return value from std::cin.getline() for
> > end-of-file. You are not testing it for any error. Always test return 
> > values.
> My program is a quick-and-dirty way to simulate the actual program I am 
> trying to use.
> I have no access to the code and all I know about it is that when I enter a 
> command, it responds and the only way to kill it is with -C.

Ah, I guess I missed the significance of the word "suppose"...

> > In your script, the end of the here document will cause your program to see
> > end-of-file (this is NOT the string "EOF" - that's just the way you denote
> > the end of the here doc).
> I am aware of that. I'm trying to find a way to send the program -C 
> from the script.

I don't believe that is possible. ^C is not part of the data stream read by the 
program.
What happens is that when you press ^C, your terminal driver notices it, 
swallows it,
and sends an INTR signal to the process attached to the terminal. It is that 
INTR
signal that kills the program, if it has not been written to capture and handle 
that signal.
When reading the data from a file or here document, that data doesn't go via 
the terminal driver.

> > And you really ought to find a forum or mailing list where this kind of
> > question is ON-topic. Flagging the subject OT isn't a magic permission
> > to post anything you like!
> I agree, I really ought to.

Cheers
Tony
-- 
Tony Mountifield
Work: t...@softins.co.uk - http://www.softins.co.uk
Play: t...@mountifield.org - http://tony.mountifield.org
___
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos


Re: [CentOS] [OT] bash here documents

2013-06-24 Thread Les Mikesell
On Mon, Jun 24, 2013 at 12:36 PM, Steve  wrote:
>
> My junk program is a quick-and-dirty simulation if the actual program I am 
> trying to use.
> I do not have the code for the program and all I know is that it responds to 
> command input and the only way to terminate it is with .

It is somewhat hard to believe that the 'real' program would not exit
when it hits the end-of-file, which you would simulate with 
at the terminal and the end of a here document will also provide.
What happens if you run the real program with input redirected from a
file - does the machine melt as it keeps on reading?

> If I run my junk program directly, I get:
>
> $ ./junk
> blah
> response to blah
> bleh
> response to bleh
> ^C
> $
>
> I want to be able to get the same output from the script AND have the script 
> end and not hang waiting for more input.

Are you sure it won't end with a typed ^D as the only thing typed?
If it really needs the ^C you'll have to do something ugly to kill it
with a signal.

--
   Les Mikesell
 lesmikes...@gmail.com
___
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos


Re: [CentOS] [OT] bash here documents

2013-06-24 Thread Steve

 m.r...@5-cent.us wrote: 
> Steve wrote:
> > Suppose I have this C++ program:
> > #include 
> > int main (int argc, char** argv)
> > {
> > while (1)
> > {
> > char cmd[80];
> > std::cin.getline(cmd, 80);
> > std::cout << "response to " << cmd << std::endl;
> > }
> > }
> >
> > compiled by: c++ -o junk junk.cpp
> >
> > and I have this bash script:
> > #!/bin/bash
> > ./junk < > blah
> > bleh
> > \cC
> > EOF
> > echo "Something else"
> >
> > When I run the script, the program starts and waits for input forever.
> > I have 2 questions:
> > 1) The "blah" and "bleh" line are not echoed to cout. Why not? Does the
> > here document not send the data to stdin?
> > 2) How do I terminate the program? When run interactively, I use -C.
> 
> I've only done a tiny bit of C++, but a bunch of years of C. First, I
> think the \cC is doing something odd; in vi, I'd have tried typing it in
> with . Second, do you want the output to be "blah bleh"?
I have also tried with  and got the same results.
 
> Finally, I am *very* strongly *not* a fan of while. If I have to use it, I
> set *some* limit - in this case, I'd look for an end-of-file, or some word
> you decide for "stop here".
> 
> As the old joke goes, about hunting elephants in Africa, a programmer sets
> up a search patter up, across, up, back, starting in Capetown and ending
> in Cairo.
> 
> The *experienced* programmer puts an elephant in the zoo in Cairo to
> ensure termination of the loop.
My junk program is a quick-and-dirty simulation if the actual program I am 
trying to use.
I do not have the code for the program and all I know is that it responds to 
command input and the only way to terminate it is with .
If I run my junk program directly, I get:

$ ./junk
blah
response to blah
bleh
response to bleh
^C
$

I want to be able to get the same output from the script AND have the script 
end and not hang waiting for more input.

Steve
___
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos


Re: [CentOS] [OT] bash here documents

2013-06-24 Thread Steve

 Tony Mountifield  wrote: 
> In article <20130624135817.10QZO.129278.root@cdptpa-web19-z02>,
> Steve  wrote:
> > Suppose I have this C++ program:
> > #include 
> > int main (int argc, char** argv)
> > {
> > while (1)
> > {
> > char cmd[80];
> > std::cin.getline(cmd, 80);
> > std::cout << "response to " << cmd << std::endl;
> > }
> > }
> > 
> > compiled by: c++ -o junk junk.cpp
> > 
> > and I have this bash script:
> > #!/bin/bash
> > ./junk < > blah
> > bleh
> > \cC
> > EOF
> > echo "Something else"
> > 
> > When I run the script, the program starts and waits for input forever.
> > I have 2 questions:
> > 1) The "blah" and "bleh" line are not echoed to cout. Why not? Does the 
> > here document not send the data to stdin?
> > 2) How do I terminate the program? When run interactively, I use -C. 
> 
> You should be testing the return value from std::cin.getline() for
> end-of-file. You are not testing it for any error. Always test return values.
My program is a quick-and-dirty way to simulate the actual program I am trying 
to use.
I have no access to the code and all I know about it is that when I enter a 
command, it responds and the only way to kill it is with -C.

> In your script, the end of the here document will cause your program to see
> end-of-file (this is NOT the string "EOF" - that's just the way you denote
> the end of the here doc).
I am aware of that. I'm trying to find a way to send the program -C from 
the script.

> And you really ought to find a forum or mailing list where this kind of
> question is ON-topic. Flagging the subject OT isn't a magic permission
> to post anything you like!
I agree, I really ought to.
___
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos


Re: [CentOS] [OT] bash here documents

2013-06-24 Thread m . roth
Steve wrote:
> Suppose I have this C++ program:
> #include 
> int main (int argc, char** argv)
> {
> while (1)
> {
> char cmd[80];
> std::cin.getline(cmd, 80);
> std::cout << "response to " << cmd << std::endl;
> }
> }
>
> compiled by: c++ -o junk junk.cpp
>
> and I have this bash script:
> #!/bin/bash
> ./junk < blah
> bleh
> \cC
> EOF
> echo "Something else"
>
> When I run the script, the program starts and waits for input forever.
> I have 2 questions:
> 1) The "blah" and "bleh" line are not echoed to cout. Why not? Does the
> here document not send the data to stdin?
> 2) How do I terminate the program? When run interactively, I use -C.

I've only done a tiny bit of C++, but a bunch of years of C. First, I
think the \cC is doing something odd; in vi, I'd have tried typing it in
with . Second, do you want the output to be "blah bleh"?

Finally, I am *very* strongly *not* a fan of while. If I have to use it, I
set *some* limit - in this case, I'd look for an end-of-file, or some word
you decide for "stop here".

As the old joke goes, about hunting elephants in Africa, a programmer sets
up a search patter up, across, up, back, starting in Capetown and ending
in Cairo.

The *experienced* programmer puts an elephant in the zoo in Cairo to
ensure termination of the loop.

  mark

___
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos


Re: [CentOS] [OT] bash here documents

2013-06-24 Thread Tony Mountifield
In article <20130624135817.10QZO.129278.root@cdptpa-web19-z02>,
Steve  wrote:
> Suppose I have this C++ program:
> #include 
> int main (int argc, char** argv)
> {
> while (1)
> {
> char cmd[80];
> std::cin.getline(cmd, 80);
> std::cout << "response to " << cmd << std::endl;
> }
> }
> 
> compiled by: c++ -o junk junk.cpp
> 
> and I have this bash script:
> #!/bin/bash
> ./junk < blah
> bleh
> \cC
> EOF
> echo "Something else"
> 
> When I run the script, the program starts and waits for input forever.
> I have 2 questions:
> 1) The "blah" and "bleh" line are not echoed to cout. Why not? Does the here 
> document not send the data to stdin?
> 2) How do I terminate the program? When run interactively, I use -C. 

You should be testing the return value from std::cin.getline() for
end-of-file. You are not testing it for any error. Always test return values.

In your script, the end of the here document will cause your program to see
end-of-file (this is NOT the string "EOF" - that's just the way you denote
the end of the here doc).

And you really ought to find a forum or mailing list where this kind of
question is ON-topic. Flagging the subject OT isn't a magic permission
to post anything you like!

Cheers
Tony
-- 
Tony Mountifield
Work: t...@softins.co.uk - http://www.softins.co.uk
Play: t...@mountifield.org - http://tony.mountifield.org
___
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos


[CentOS] [OT] bash here documents

2013-06-24 Thread Steve
Suppose I have this C++ program:
#include 
int main (int argc, char** argv)
{
while (1)
{
char cmd[80];
std::cin.getline(cmd, 80);
std::cout << "response to " << cmd << std::endl;
}
}

compiled by: c++ -o junk junk.cpp

and I have this bash script:
#!/bin/bash
./junk <-C. 

Thanks,
Steve
___
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos