473,789 Members | 2,703 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 25233
In 'comp.lang.c', ni********@hotm ail.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**********@no os.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********@hot mail.com> wrote in message
news:bf******** *************** ***@posting.goo gle.com...
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("somethi ng");

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

system("abc\"de f\"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.n et> writes:
On Mon, 07 Jul 2003 18:24:13 -0400, Eric Sosman <Er*********@su n.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_Keit h) 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**********@n oos.fr> wrote:
In 'comp.lang.c', ni********@hotm ail.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.n et> writes:
On Mon, 07 Jul 2003 18:24:13 -0400, Eric Sosman <Er*********@su n.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 "technicall y correct" English; but since when was rock & roll "technicall y correct"?
Nov 13 '05 #9

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

Similar topics

1
2363
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 codes for the function? Any help is most appreciated. -- Randy Jackson http://fourcolorexplosion.com
1
1756
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 performing this command it can't close the MS DOS prompt window and return from it . I want to know how I can solve this problem and if there is another way to execute (*.exe) within visual c++ program. Thanks.
22
2849
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 int. I would like to know how could this is done? I can see only one way currently and I know that there must be a better method. Right now I would be tempted to pipe the output of the command to a temp file and then get the data from the file....
16
2156
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 which meansthe command could not be executed. Kindly help me............
2
2421
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 ask me to enter 'Y' and if I press enter it will generate some files. So here I used system("dnaml")
12
2072
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 present working directory.Am having certain doubts about this program.
3
2465
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 is from the windows cmd.exe that is executed by the system function. i need to prevent the window from being displayed and would prefer doing so from the c++ code (may not get access to c library source). any suggestions? yes, i'm a newbie.
2
2899
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
1994
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 fork-execl() pair and then making an interprocess communication between these two(parent-child process). But the problem is that somewhere in exec() function which is working on some machines and failing on a few machines. So anybody if have any...
0
9666
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10410
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10200
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10139
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9984
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7529
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5418
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5551
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2909
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.