Invoking other executable prgms using C?

P

Pravin

hi

Is it possible to open an executable program like NOTEPAD(win)
using C-Program...(other than the function system() )? if so,please
provide me with an eg code...if not why?

Thanks in advance.
 
A

Anand

Pravin said:
hi

Is it possible to open an executable program like NOTEPAD(win)
using C-Program...(other than the function system() )? if so,please
provide me with an eg code...if not why?

Thanks in advance.
When you said "open" I presume you meant "execute". If you want to
really just open a file, the fopen is there to help you.

If you want to execute any program, then the only standard C call is
system().

<OT Call="POSIX">
My system has another set of calls exec* (execl,execv, etc.)
(#include <unistd.h>), which comes close (but for sure it's not same.)
You could refer the manuals of your compiler to see if it has something
similar and it has things that meets your needs.

However, note that this is Off-Topic to discuss further about
non-standard C calls further here. If you further have doubts regarding
the call, then please take to relevant (OS and/or Compiler specific) group.
</OT>
 
K

Keith Thompson

Pravin said:
Is it possible to open an executable program like NOTEPAD(win)
using C-Program...(other than the function system() )? if so,please
provide me with an eg code...if not why?

There is no way in standard C to execute another program other than
the system() function. There may be other methods available on your
system; if you want more information, you'll need to ask in a
newsgroup that's specific to your system (not comp.lang.c).
 
B

Bob Eager

Is it possible to open an executable program like NOTEPAD(win)
using C-Program...(other than the function system() )? if so,please
provide me with an eg code...if not why?

If you want a Windows-specific answer (as your question sort of implies)
then you might do better to crosspost to a Windows programming newsgroup
- posting to an OS/2 programming group won't help much!

OTOH, if it *is* OS/2 help you require, please ask again.
 
J

Jordan Abel

When you said "open" I presume you meant "execute". If you want to
really just open a file, the fopen is there to help you.

If you want to execute any program, then the only standard C call is
system().

<OT Call="POSIX">
My system has another set of calls exec* (execl,execv, etc.)
(#include <unistd.h>), which comes close (but for sure it's not same.)
You could refer the manuals of your compiler to see if it has something
similar and it has things that meets your needs.

However, note that this is Off-Topic to discuss further about
non-standard C calls further here. If you further have doubts regarding
the call, then please take to relevant (OS and/or Compiler specific) group.
<OT more>
However, he's unlikely to be able to run "NOTEPAD (win)" with exec* -
for that he probably needs CreateProcess or CreateProcessEx - that
should give him enough to google for if he can't find an appropriate
windows-specific newsgroup.
 
P

Peter Flass

Bob said:
If you want a Windows-specific answer (as your question sort of implies)
then you might do better to crosspost to a Windows programming newsgroup
- posting to an OS/2 programming group won't help much!

OTOH, if it *is* OS/2 help you require, please ask again.

There are lots of ways in OS/2...
 
C

Christopher Benson-Manica

C

Chuck F.

Christopher said:
(F'ups not set.)


As noted, there is a very narrow C answer to this question. I
suspect you could benefit from a visit to the following URLs.

http://www.ungerhu.com/jxh/clc.welcome.txt
http://www.eskimo.com/~scs/C-faq/top.html
http://benpfaff.org/writings/clc/off-topic.html

Why are you indulging in this campaign to revise all subject lines
to "[MTA]"?

--
Some informative links:
http://www.geocities.com/nnqweb/
http://www.catb.org/~esr/faqs/smart-questions.html
http://www.caliburn.nl/topposting.html
http://www.netmeister.org/news/learn2quote.html
 
C

Christopher Benson-Manica

(Groups trimmed to comp.lang.c)
Why are you indulging in this campaign to revise all subject lines
to "[MTA]"?

It was suggested as more fitting than "OT" for Meta Topical Advice,
and it sounded reasonable to me. If it's doing more harm than good,
I'll be happy to continue using "OT".
 
C

Chuck F.

Christopher said:
(Groups trimmed to comp.lang.c)
Why are you indulging in this campaign to revise all subject
lines to "[MTA]"?

It was suggested as more fitting than "OT" for Meta Topical
Advice, and it sounded reasonable to me. If it's doing more
harm than good, I'll be happy to continue using "OT".

You may have noticed that the better newsreaders also automatically
remove the "(was ...)", thus convincing the stupider newsreaders
that the thread is new. Thus my choice of 'revise' above.

--
Some informative links:
http://www.geocities.com/nnqweb/
http://www.catb.org/~esr/faqs/smart-questions.html
http://www.caliburn.nl/topposting.html
http://www.netmeister.org/news/learn2quote.html
 
C

Christopher Benson-Manica

Chuck F. said:
You may have noticed that the better newsreaders also automatically
remove the "(was ...)", thus convincing the stupider newsreaders
that the thread is new. Thus my choice of 'revise' above.

I use tin, and it isn't always correct when it makes netiquette
suggestions; this may be such an instance. Would it be preferable,
then, to simply prepend [MTA] and dispense with the (was:...)?
 
C

Chuck F.

Christopher said:
Chuck F. said:
You may have noticed that the better newsreaders also
automatically remove the "(was ...)", thus convincing the
stupider newsreaders that the thread is new. Thus my choice
of 'revise' above.

I use tin, and it isn't always correct when it makes netiquette
suggestions; this may be such an instance. Would it be
preferable, then, to simply prepend [MTA] and dispense with the
(was:...)?

Damfiknow. I do know that MTA is meaningless to me, while OT does
imply an opinion.

--
Some informative links:
http://www.geocities.com/nnqweb/
http://www.catb.org/~esr/faqs/smart-questions.html
http://www.caliburn.nl/topposting.html
http://www.netmeister.org/news/learn2quote.html
 
P

Peter Koller

Pravin said:
hi

Is it possible to open an executable program like NOTEPAD(win)
using C-Program...(other than the function system() )? if so,please
provide me with an eg code...if not why?

Thanks in advance.

Dead easy:-

BOOL StartProgram(PCHAR program, PCHAR params)
{
STARTDATA SData = {0};
APIRET rc = 0;
PID pid = 0;
ULONG ulSessID = 0;
char achObjBuf[256] = {0};

SData.Length = sizeof(STARTDATA);
SData.Related = SSF_RELATED_INDEPENDENT;
SData.FgBg = SSF_FGBG_FORE;
SData.TraceOpt = SSF_TRACEOPT_NONE;
SData.PgmTitle = NULL;
SData.PgmName = program;
SData.PgmInputs = params;
SData.TermQ = NULL;
SData.InheritOpt = SSF_INHERTOPT_PARENT;
SData.SessionType = SSF_TYPE_DEFAULT;
SData.PgmControl = SSF_CONTROL_VISIBLE;
SData.ObjectBuffer = achObjBuf;
SData.ObjectBuffLen = 256;
rc = DosStartSession(&SData, &ulSessID, &pid);
if(rc != 0) return(FALSE);
return(TRUE);
}


...at least that is how it's done in OS/2

Yours,
Peter
 
F

Flash Gordon

BOOL StartProgram(PCHAR program, PCHAR params)

<snip OS2 specific answer.
..at least that is how it's done in OS/2

On comp.lang.c we only deal with standard C so please be so good as to
set follow-ups to exclude comp.lang.c when proposing system specific
answers so we don't have to put up with discussions about OS/2 which I'm
sure are perfectly reasonable over on comp.os.os2.programmer.misc.
 
B

Bob Eager

<snip OS2 specific answer.


On comp.lang.c we only deal with standard C so please be so good as to
set follow-ups to exclude comp.lang.c when proposing system specific
answers so we don't have to put up with discussions about OS/2 which I'm
sure are perfectly reasonable over on comp.os.os2.programmer.misc.

If you deal only in standard C, then the question (which excluded
'system() ' as a solution) shouldn't have been posted there in the first
place!
 
M

Michael Rasmussen

Is it possible to open an executable program like NOTEPAD(win)
using C-Program...(other than the function system() )? if so,please
provide me with an eg code...if not why?
popen-> man popen
 
K

Keith Thompson

Bob Eager said:
If you deal only in standard C, then the question (which excluded
'system() ' as a solution) shouldn't have been posted there in the first
place!

The question, "Is it possible ...", is perfectly appropriate.
The answer is No.

And why is system() not an acceptable solution in the first place?

(comp.os.os2.programmer.misc dropped from Newsgroups header.)
 
F

Flash Gordon

Peter said:
When the question is cross-posted, so should the reply be.

Flash Gordon wrote:

I asked for follow-ups to be set so the discussion gets directed only to
where it is topical. Or do you think that if someone starts a cross post
to a group you read that is off topic the cross-post should continue?
How about if a hundred people do it? How about if they do it with a
hundred threads each with 10 posts per day?

You might not care about keeping groups you read topical, but we (most
of the regulars on comp.lang.c) care about keeping comp.lang.c topical.

Also, top posting is not considered acceptable on comp.lang.c, if it is
acceptable on comp.os.os2.programmer.misc then that is another reason to
set follow-ups to only one group.

Note that I did not set follow ups because discussion of whether
something should be cross-posted is a discussion of topicality, and
those are generally considered topical everywhere.
 
C

CBFalconer

Peter said:
When the question is cross-posted, so should the reply be.

No. The question should have follow-ups set to a single
newsgroup. And those follow-ups should never be top-posted.

--
"The power of the Executive to cast a man into prison without
formulating any charge known to the law, and particularly to
deny him the judgement of his peers, is in the highest degree
odious and is the foundation of all totalitarian government
whether Nazi or Communist." -- W. Churchill, Nov 21, 1943
 

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

Forum statistics

Threads
473,772
Messages
2,569,593
Members
45,109
Latest member
JanieMalco
Top