[Tfug] Diverted stdin problem

jblais joe.blais at pti-instruments.com
Thu Dec 6 17:45:54 MST 2007


I'm replying to myself but--
Might
 $ execl( "/bin/bash",  ....
be better than
 $ execl( "/bin/sh",  ....
-- is sh a link to bash, thus getting me yet one more level deeper so that
<   doesn't work anymore?
Joe


> -----Original Message-----
> From: tfug-bounces at tfug.org [mailto:tfug-bounces at tfug.org]On Behalf Of
> jblais
> Sent: Wednesday, December 05, 2007 10:07 AM
> To: Tfug
> Subject: [Tfug] Diverted stdin problem
>
>
> Hello -
>
> Thanks for all the help in the past - here's a new "problem" or
> "opportunity
> for improvement"  :-(
>
> I have 2 virtual PC's running on XP :-| Each is loaded with Fedora Core 5,
> each was installed/loaded separately so I don't remember all the
> selections.
> I think one is like the "everything" bagel.  Then I have a Linux partition
> on the same PC, with the same version. And then I have a handful of
> instruments, again with the same version.  These were from an install that
> we "ghosted"
>
> On these I have a small app that I found, with the help of Tfug, called
> email.  It simply sends emails.  You can call it one way and it
> will invoke
> vi to edit the email.  Or you can redirect a text file to stdin, and that
> will be sent.  When it sends it puts a copy of the sent email, with nitty
> gritty email header junk, into a file called sent.mail.
>
> On all the machines I can successfully send an email manually, doing this
> from a cmd line:
> $ email -s 'subject of email' my.email at my.company.com
> This works every time, invoking vi.
>
> I can also do:
> $ email -t
> This simply tests my config file that has parms in it like server, port,
> password.... and it works.
>
> I can also do this from the cmd line:
> $ email -s 'subject of email' my.email at my.company.com < /tmp/Outbound.txt
> This too works every time, manually, sending the outbound text without
> invoking vi.
>
> I can put the above line into a script file and successfully send email.
>
> Now, I have a C++ program, that simply creates a file at /tmp/Outbound.txt
> and calls:
>   system( "email -s 'subject of email' my.email at my.company.com <
> /tmp/Outbound.txt" ) ;
> I've also done  (something like this):
>   pid = fork();
>   if ( pid == 0 )
>   {
>     execpl( "/bin/sh", "sh", "-c", "email -s 'subject of email'
> my.email at my.company.com < /tmp/Outbound.txt", 0 ) ;
>     exit(1) ;
>   }
>
> The bit of magic works on one virtual pc, and all my instruments.  On the
> other virtual pc, and my linux partition, it fails with somethig like:
> email:  ERROR: Smtp 500 unrecognized command
>
> So I searched the web for the '500 error', and examples point to
> things like
> not having a <crlf> or something in the command line.  SO I tried
> all manner
> of stuff to fix that, even the fork();exec() stuff, rather than system()
> which apparently can have issues if the application has the permission to
> change user ID or whatever. -- this is because of some security stuff
> (?political stuff like SE Linux and the NSA? conspiricy everywhere!-)  --
> and perhaps where one install differs from another - if that's
> the problem--
> opportunity:-)
>
> So anyway-- this fails on 2 out of 4 machines, each installed
> with the same
> version of Fedora Linux.
>   system( "email -s 'subject of email' my.email at my.company.com <
> /tmp/Outbound.txt" ) ;
>
> but this works...(on the ones that otherwise fail):
>   system( "email -s 'subject of email' my.email at my.company.com" ) ;
> but the way it works is a bit unexpected.  vi doesn't come up as
> the editor,
> instead, the body of the email (which is successfully sent) is
> the text (the
> nitty gritty portion anyway) that normally gets put into the the sent.mail
> log file!
>
> So, on some installs, the redirect of the desired text file to
> stdin, of the
> email that is invoked by the system() call, works correctly, and on others
> the " < /tmp/junk.txt" fails, and instead (probably) the redirected stdout
> which would normally be appended to the sent.mail file, is
> instead diverted
> to stdin, as the message!
>
> I even tried calling the script which works when called manually, and it
> fails with the same error.
>   system( "./SendScript" ) ;
>
> I have the whole mess working on my instruments so I'm kind of OK, but why
> does it work on one install, and not on another?
>
> Thanks
>
> Joe
>
>
>
>
>
>
>
>
>
> _______________________________________________
> Tucson Free Unix Group - tfug at tfug.org
> Subscription Options:
> http://www.tfug.org/mailman/listinfo/tfug_tfug.org





More information about the tfug mailing list