473,419 Members | 2,074 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,419 software developers and data experts.

Send email using system( ) function

Hi,

I am trying to writing a c program to send email using system()
function call on Unix(Sun Solaris). I tried the following:

#include <stdio.h>
#include <stdio.h>

int main(void)
{
system('mailx -s "Hello" js****@hotmail.com < attached_file');
return 0;
}

This doesn't seem to work. I would appreciate any advice.

Thanks in advance.

Nick
Nov 13 '05 #1
8 25194
In 'comp.lang.c', ni********@hotmail.com (Nick Li) wrote:
#include <stdio.h>
#include <stdio.h>

int main(void)
{
system('mailx -s "Hello" js****@hotmail.com < attached_file');
Try that:

system("mailx -s \"Hello\" js****@hotmail.com < attached_file");

return 0;
}

--
-ed- em**********@noos.fr [remove YOURBRA before answering me]
The C-language FAQ: http://www.eskimo.com/~scs/C-faq/top.html
<blank line>
FAQ de f.c.l.c : http://www.isty-info.uvsq.fr/~rumeau/fclc/
Nov 13 '05 #2

Nick Li <ni********@hotmail.com> wrote in message
news:bf**************************@posting.google.c om...
Hi,

I am trying to writing a c program to send email using system()
function call on Unix(Sun Solaris). I tried the following:

#include <stdio.h>
#include <stdio.h>

int main(void)
{
system('mailx -s "Hello" js****@hotmail.com < attached_file');
return 0;
}

This doesn't seem to work. I would appreciate any advice.
'system()'s argument must be a 'C-style' string
(zero-terminated array of characters.) C-style
string literals are expressed by putting them
between a pair of double quotes ("). That's not
what you have above.

system("something");

If your string itself needs to contain double quotes,
use the corresponding escape sequence:

system("abc\"def\"ghi"); /* sends the string abd"def"ghi */
/* to the command processor */

-Mike


Thanks in advance.

Nick

Nov 13 '05 #3
Alan Balmer wrote:

Your immediate problem is answered else-thread. A minor point - check
the return value from system(). If it's actually the last statement in
the program, you can use

return (system('mailx -s "Hello" js****@hotmail.com <
attached_file'));

If it's used in a script, the script can check the success of the
call.


The value returned by system() is implementation-defined,
and may or may not have anything to do with the exit status
of the invoked program.

On Solaris, system() happens to return an encoding of the
exit status of the invoked shell -- but this behavior isn't
guaranteed for all C implementations, and besides the encoding
isn't itself immediately meaningful as an exit status.

--
Er*********@sun.com
Nov 13 '05 #4


Alan Balmer wrote:
Your immediate problem is answered else-thread. A minor point - check
the return value from system(). If it's actually the last statement in
the program, you can use

return (system('mailx -s "Hello" js****@hotmail.com <
attached_file'));

If it's used in a script, the script can check the success of the
call.


Maybe, maybe not. There's no guarantee on what if any return there is
from system() other than when the argument is NULL to check for the
presence of a command processor.


Brian Rodenborn
Nov 13 '05 #5
Alan Balmer <al******@att.net> writes:
On Mon, 07 Jul 2003 18:24:13 -0400, Eric Sosman <Er*********@sun.com>
wrote: [...]
The value returned by system() is implementation-defined,
and may or may not have anything to do with the exit status
of the invoked program.

Implementation defined, yes, but defined by the same implementation on
which the program is being executed,


Agreed.
thus likely to be consistent with
any shell implemented on the same system.


Not necessarily. In particular,

<OT>
you might want to try the following on your Solaris system:

#include <stdio.h>
#include <stdlib.h>

int main(void)
{
int result = system("/bin/false");
printf("result = %d\n", result);
return result;
}

"/bin/false" does an "exit 255". The value returned by system() is
65280, or 255 << 8. When you return this value from the main program,
all but the low-order 8 bits are stripped off, leaving 0.
</OT>

The details are, of course, implementation-defined; the point is that
they can be implementation-defined in surprising ways, even on systems
you're familiar with.

--
Keith Thompson (The_Other_Keith) ks*@cts.com <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://www.sdsc.edu/~kst>
Schroedinger does Shakespeare: "To be *and* not to be"
Nov 13 '05 #6
Emmanuel Delahaye <em**********@noos.fr> wrote:
In 'comp.lang.c', ni********@hotmail.com (Nick Li) wrote:
#include <stdio.h>
#include <stdio.h>

int main(void)
{
system('mailx -s "Hello" js****@hotmail.com < attached_file');


Try that:

system("mailx -s \"Hello\" js****@hotmail.com < attached_file");


And for completeness, #include <stdlib.h> instead of #including
<stdio.h> - twice!

Richard
Nov 13 '05 #7
On Tue, 08 Jul 2003 07:24:11 GMT, Keith Thompson <ks*@cts.com> wrote:
Alan Balmer <al******@att.net> writes:
On Mon, 07 Jul 2003 18:24:13 -0400, Eric Sosman <Er*********@sun.com>
wrote:[...]

<snip><OT>
you might want to try the following on your Solaris system:

#include <stdio.h>
#include <stdlib.h>

int main(void)
{
int result = system("/bin/false");
printf("result = %d\n", result);
return result;
}

"/bin/false" does an "exit 255". The value returned by system() is
65280, or 255 << 8. When you return this value from the main program,
all but the low-order 8 bits are stripped off, leaving 0.
</OT>

The details are, of course, implementation-defined; the point is that
they can be implementation-defined in surprising ways, even on systems
you're familiar with.


Actually, I don't have a Solaris system :-) Believe it or not, I
don't find the result surprising - I would expect some such. It's been
a while since I read the (several pages of) POSIX spec on this
subject, but I seem to remember that only 8 bits are returned from
main, but the system call would return (for success) 0 in the lower 8
bits and further information in the upper bits, which can always be
decoded by the standard macros. I have a local campaign going to get
maintenance programmers to change the "exit(-1)" our code is liberally
sprinkled with.

--
Al Balmer
Balmer Consulting
re************************@att.net
Nov 13 '05 #8
Groovy hepcat Nick Li was jivin' on 7 Jul 2003 14:14:28 -0700 in
comp.lang.c.
Send email using system( ) function's a cool scene! Dig it!
I am trying to writing a c program to send email using system()
function call on Unix(Sun Solaris). I tried the following:

#include <stdio.h>
#include <stdio.h>


One more point others seem to have missed: you have included stdio.h
twice. You need to include stdlib.h for the system() function.

--

Dig the even newer still, yet more improved, sig!

http://alphalink.com.au/~phaywood/
"Ain't I'm a dog?" - Ronny Self, Ain't I'm a Dog, written by G. Sherry & W. Walker.
I know it's not "technically correct" English; but since when was rock & roll "technically correct"?
Nov 13 '05 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Randy Jackson | last post by:
I'm attempting to debug some code that uses the System function. When the function is called, it returns Error 1. Does anyone know what that error might be, or where I can find a list of error...
1
by: Leila Y | last post by:
Dear Friends, I need to execute an executable file (*.exe) within visual c++ program. I have used " system function " for this purpose and it works in most of the time but sometimes while...
22
by: SF | last post by:
Hello All, In a windows C learning project I am wokring on I use the system function to run a command, I want to suck the results into a vairable. The system function seems to only return an...
16
by: BHARAT MEHTA | last post by:
Hi Guys, I am little new to C. I wish to know the way to use the 'system' function. I mean I know that the function is used to run an external DOS command but every time I use it it returns -1...
2
by: nnandini8 | last post by:
Hello Guys, I have a doubt in system() function. I need to implement the certain command line arguements in a program. For Example if I type "dnaml" at command line and press enter then it will...
12
by: sunil | last post by:
Hi All, Please have a look the below program #include<stdlib.h> int i = system("pwd"); I compiled the above program in UNIX ,it got compiled and executed with out any errors.It prints the...
3
by: extrnh | last post by:
i have a c++ program compiled in visual c++ that links to a c library. when a system function is called in the c library a blank command window is displayed while the c logic is executing. this...
2
by: Eran.Yasso | last post by:
Hi, I saw that there's the delegate feature that handles as pointer to function but in safe mode. Can I send function name to other function to call it? for example: printmeA() {
0
by: rajarora | last post by:
Hi , Is there anybody who have any idea of any System Function in C/C++ for Sun-Solaris (unix) platform which can serve the alternative of execl() system function. Actually I am calling a...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.