how execute exe in c

C

chellappa

Hello,

I would like to know how i can execute an exe file using c prgogram? I
am using the GNU GCC in Linux Could someone explain me how to do that ?
send mail chellappa at gmail .com
Thanks in advance...
Regards
chellappa
 
J

jaekkay

I think execution of system() function is OS specific. The parameter
passed to the system() function will be executed by the native OS
runtime environment. So i think system(.exe) in linux will not get
executed.
 
P

Pacher R. Dragos

chellappa said:
Hello,

I would like to know how i can execute an exe file using c prgogram? I
am using the GNU GCC in Linux Could someone explain me how to do that ?
send mail chellappa at gmail .com
Thanks in advance...
Regards
chellappa


system("command") is a good choice, but you can do It more "leet", like
defining a char where you store your exe hex values, then execute it
through a pointer from a stream, or something like that.
For 99% of users the first choice is the most common, that if you
don't plan to do something unusual like in the second choice :)
 
C

Christopher Benson-Manica

jaekkay said:
I think execution of system() function is OS specific. The parameter
passed to the system() function will be executed by the native OS
runtime environment. So i think system(.exe) in linux will not get
executed.

First of all, it seems OP was talking about an "executable file", not
an "exe", so there is no reason to expect system( "/bin/ls" ), for
example, not to work. Also...

It is proper Usenet etiquette to include the relevant portions of the text
you are replying to. To do this using Google groups, please follow the
instructions below, penned by Keith Thompson:

If you want to post a followup via groups.google.com, don't use
the broken "Reply" link at the bottom of the article. Click on
"show options" at the top of the article, then click on the
"Reply" at the bottom of the article headers.
 
F

Flash Gordon

jaekkay said:
I think execution of system() function is OS specific. The parameter
passed to the system() function will be executed by the native OS
runtime environment. So i think system(.exe) in linux will not get
executed.

Please provide context when posting, there is absolutely no guarantee
that other people will *ever* see the post you are replying to. Search
this group for "google context" without the quotes to see the hundreds
of messages telling people how to post correctly using google. Then
complain at Google for them making you look like an idiot.

As to what you are saying, it is even worse than you thought. The string
is actually passed to the shell to be executed, so the behaviour depends
not just on the OS but on the behaviour of the default shell (what you
have as /bin/sh on Linux).

However, depending on how you Linux system is configured you might well
be able to run a DOS or Windows application by doing
system("app.exe");

Doing so is the *only* support in standard C for running another
executable from within a C program. If that is not enough then the OP
needs to ask on a Linux group.
 
J

jaekkay

I am sorry for that. This is the first time that i am posting a reply.
I should have read the procedures before posting.
 
F

Flash Gordon

Pacher said:
system("command") is a good choice, but you can do It more "leet", like
defining a char where you store your exe hex values, then execute it
through a pointer from a stream, or something like that.

If by "leet" you mean completely stupid or brain dead, then possibly.
However, on a number of systems this will not work, and the number of
systems it does not work is more likely to increase than decrease.
For 99% of users the first choice is the most common, that if you
don't plan to do something unusual like in the second choice :)

When system is not suitable you go to system specific extensions like
the exec family of functions provided on *nix, you don't go to stupid
tricks like you suggested.
 
T

Tom

Doing so is the *only* support in standard C for running another
executable from within a C program. If that is not enough then the OP
needs to ask on a Linux group.

flash, are you sure that this is the only support to run another program..?
ya you are correct when you say standard C,
but considering that OP is trying to run his executable on a linux OS, you
can always do an exec call
like :
execl("/usr/bin/date","date",0);So, if OP was particular on getting this
program running, then he can as well, use this method to run his executable.
 
C

Christopher Benson-Manica

Tom said:
flash, are you sure that this is the only support to run another program..?
ya you are correct when you say standard C,

And that's all that matters in this newsgroup.
execl("/usr/bin/date","date",0);So, if OP was particular on getting this
program running, then he can as well, use this method to run his executable.

Then OP could head to a system-specific newsgroup to get help with
that.
 
M

Martin Ambuhl

chellappa said:
Hello,

I would like to know how i can execute an exe file using c prgogram? I
am using the GNU GCC in Linux Could someone explain me how to do that ?
send mail chellappa at gmail .com

Even though it is considered a poor idea, and sometimes considered rude,
to ask for e-mail responses, I am e-mailing this as well as posting it.
There are several reasons that you don't want responses by e-mail, but
the most important is that you have no way of judging the answers you
get. When an answer is posted to the newsgroup, it is subject to the
scrutiny of other posters and so can be corrected when wrong,
incomplete, or misleading.

The simple answer to your question is to use system(). It is documented
both in the docs for your implementation and in even the most basic C
text.

There are other approaches that are specific to certain platforms or
implementations. Among the more used are the exec*() family which is
POSIX and the spawn*() family which is not. Neither of these is
necessarily present in a C implementation, since they are non-standard.
That makes them off-topic in <so if you choose to
use them questions belong in newsgroups specific to your platform or C
implementation.
Thanks in advance...

That is often considered rude, since it presumes relationships of
expectation and obligation.

But that's nice.
 
C

Christopher Benson-Manica

That is often considered rude, since it presumes relationships of
expectation and obligation.

Do you think so? I've always considered it to be friendly, but
perhaps that's just me.
 
R

Rich Gibbs

Christopher Benson-Manica said the following, on 10/21/05 11:27:
Do you think so? I've always considered it to be friendly, but
perhaps that's just me.

I've usually regarded it as friendly, too, unless the overall tone of
the message suggests otherwise. The argument against it, I think, is
that it might come across as "I can't be bothered to thank you after you
answer."

For that reason, I like a formula along the lines of "Thank you for your
time / interest."
 
T

Tom

And that's all that matters in this newsgroup.
i assume that , that was the premise of comp.std.c to stick to standards
strictly to C

and comp.lang.c was to tread into all paths related to C..
anyways we will let it go at that.. !

it was a good discussion.
 
F

Flash Gordon

Tom said:
flash, are you sure that this is the only support to run another program..?
ya you are correct when you say standard C,

Which is what I stated above, standard C.
but considering that OP is trying to run his executable on a linux OS, you
can always do an exec call
like :
execl("/usr/bin/date","date",0);So, if OP was particular on getting this
program running, then he can as well, use this method to run his executable.

I also stated in the above that if that was not enough ask in a Linux
group, I did this in full knowledge that in a Linux or Unix group they
can suggest lots of other ways of doing things which have advantages
over the system call (and I even know some of them myself, including the
exec family of functions). I did this because in a Linux or Unix group
they might know what is wrong with your suggestion above, which header
you failed to specify as providing the prototype etc. (I know, but that
is not for discussion here).

For the record, I also know the Windows alternatives to system, but
would no more discus those here than the POSIX ones.

So please, in future, don't follow up saying in <os-of-choice> you can
use such and such a function when people (as I did) have already
suggested going else where if the standard solution is not sufficient.
 
F

Flash Gordon

jaekkay said:
I am sorry for that. This is the first time that i am posting a reply.
I should have read the procedures before posting.

Your reply belongs *after* the text you are replying to, after anything
not relevant has been deleted, bit before. Look at the bulk of posts to
the group to see how posts should look.

<snip>
 
N

Neil Cerutti

i assume that , that was the premise of comp.std.c to stick to
standards strictly to C

When you make an assumption, it makes an ass out of you and
umption.

comp.std.c is for discussion *of* the C standard.
 
N

Neil Cerutti

Do you think so? I've always considered it to be friendly, but
perhaps that's just me.

I don't consider it rude. It is presumptious. The reader may not
choose to help you at all. I generally say something like,
"Thanks for taking the time to read my question."
 
K

Keith Thompson

Tom said:
i assume that , that was the premise of comp.std.c to stick to standards
strictly to C

and comp.lang.c was to tread into all paths related to C..
anyways we will let it go at that.. !

No, you've misunderstood the purposes of the newsgroups.

comp.lang.c is for discussion of standard C, as defined by the ISO
standard(s). (The current standard is C99, but the older C89/C90
standard is still discussed. We also sometimes discuss pre-standard C
in historical contexts.) System-specific extensions are off-topic.

comp.std.c is for discussion of the C standard as a document, not for
discussion of the language itself. For example, proposals for changes
to the standard or discussions of errors or ambiguities in the
standard belong in comp.std.c. Discussions of the language defined by
the standard belong in comp.lang.c. Discussions of things not defined
by the standard belong elsewhere.
 
M

Martin Ambuhl

To review ...
chellappa wrote near the end of his message aksing for help (by e-mail,
no less):
>Thanks in advance...

>That is often considered rude, since it presumes relationships of
>expectation and obligation.

To which we have three responses ...
Christopher Benson-Manica:
Do you think so? I've always considered it to be friendly, but
perhaps that's just me.

Rich Gibbs:
I've usually regarded it as friendly, too, unless the overall tone of the message suggests otherwise. The argument against it, I think, is that it might come across as "I can't be bothered to thank you after you answer."
For that reason, I like a formula along the lines of "Thank you for your time / interest."

Neil Cerutti:
I don't consider it rude. It is presumptious. The reader may not
choose to help you at all. I generally say something like,
"Thanks for taking the time to read my question."

The TIA cliche is well established in usenet postings, so it is no
surprise that many people use it as a "friendly" formula. But I doubt
very much that many posters use it before seeing it here. It is, rather,
from the lexicon of bill collectors, who use it and similar formulae
precisely because they set up a dominance relationship. It asserts an
expectation that certain acts are forthcoming, and that the asker has a
right to expect them. It further asserts that the time and effort of
the person answering is not worth bothering about; the asker can't be
bothered thanking for help received. "I've posted a question. You
answer it. I'm too fucking important to bother with you beyond that."
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,787
Messages
2,569,629
Members
45,330
Latest member
AlvaStingl

Latest Threads

Top