By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,515 Members | 1,848 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,515 IT Pros & Developers. It's quick & easy.

How do i Run programs

P: n/a
Hello i would like to know
which syntax do i have to use in order to make a program run other
*.exe program and also how to put inputs in it

for example i want to to make a program that run other file call
try.exe and save all the stdout into a file
thanx

May 28 '07 #1
Share this Question
Share on Google+
26 Replies


P: n/a
Chief skrev:
Hello i would like to know
which syntax do i have to use in order to make a program run other
*.exe program and also how to put inputs in it

for example i want to to make a program that run other file call
try.exe and save all the stdout into a file
thanx
I'm not sure what you mean, but this is my guess:

your_program.exe < input_file output_file

output_file ll contain same thing that you would see on your dos/shell
window
May 28 '07 #2

P: n/a
On 28 Maj, 13:36, Carramba <u...@example.netwrote:
Chief skrev:Hello i would like to know
which syntax do i have to use in order to make a program run other
*.exe program and also how to put inputs in it
for example i want to to make a program that run other file call
try.exe and save all the stdout into a file
thanx

I'm not sure what you mean, but this is my guess:

your_program.exe < input_file output_file

output_file ll contain same thing that you would see on your dos/shell
window
exec*() functions

May 28 '07 #3

P: n/a
Chief wrote:
>
Hello i would like to know which syntax do i have to use in order
? to make a program run other *.exe program and also how to put
inputs in it. for example i want to to make a program that run
other file call try.exe and save all the stdout into a file
To start with you need an OS that can run .exe files. This is
off-topic here, where we deal with the portable standard C
language. Try a newsgroup that deals with your system.

--
<http://www.cs.auckland.ac.nz/~pgut001/pubs/vista_cost.txt>
<http://www.securityfocus.com/columnists/423>
<http://www.aaxnet.com/editor/edit043.html>
<http://kadaitcha.cx/vista/dogsbreakfast/index.html>
cbfalconer at maineline dot net

--
Posted via a free Usenet account from http://www.teranews.com

May 28 '07 #4

P: n/a
Chief wrote:
Hello i would like to know
which syntax do i have to use in order to make a program run other
*.exe program and also how to put inputs in it

for example i want to to make a program that run other file call
try.exe and save all the stdout into a file
thanx
to run programs use the "system" function.

system("c:\\mydir\\myprogram.exe");
or use one of the several "exec*" functions.
May 28 '07 #5

P: n/a
Chief wrote:
Hello i would like to know
which syntax do i have to use in order to make a program run other
*.exe program and also how to put inputs in it

for example i want to to make a program that run other file call
try.exe and save all the stdout into a file
This is c.l.c FAQ, see Q 19.27 and Q 19.30.

--
Tor <torust [at] online [dot] no>
May 28 '07 #6

P: n/a
On May 28, 2:56 pm, Chief <blons...@gmail.comwrote:
Hello i would like to know
which syntax do i have to use in order to make a program run other
*.exe program and also how to put inputs in it

for example i want to to make a program that run other file call
try.exe and save all the stdout into a file

thanx
For command line program, Mr Carramba is right. But within a program,
try these stuffs

Your program, a parent process, forks a child and exec's the second
try.exe (with arguments). Close stdout for child and redirect its
output to a file using dup systemcall and pipes.

For more about fork() - see http://www.erlenstar.demon.co.uk/unix/faq_toc.html#TOC3

Here is a basic code that resembles your problem, though not same
This program pipes the o/p of 1 command to i/p of another
================================================== ==============================
#include<stdio.h>
main(){
int pfd[2] ;

if(pipe(pfd) < 0){
fprintf(stderr, "Cannot Create pipe\n");
exit(0);
}
switch(fork()){
case -1:
fprintf(stderr, "cannot create child\n");
exit(-1);
case 0:
if(dup2(pfd[1] , 1 ) < 0){
fprintf(stderr, "Cannot dup\n");
exit(0);
}
close(0) ;
close (pfd[1]);
close (pfd[0]);
execlp("ls", "ls", "-l", NULL) ;
fprintf(stderr, "Cannot exec 1\n");
default :
break ;
}
switch(fork()){
case -1:
fprintf(stderr, "Cannot fork 2\n");
exit(0);
case 0:
if(dup2(pfd[0] , 0) < 0) {
fprintf(stderr, "Cannot dup 2");
exit(0);
}
close(pfd[0]);
close(pfd[1]);
execl("/usr/bin/wc", "wc", NULL);
fprintf(stderr, "Cannot exec 2\n");
default:
break ;
}
wait ((int *)0) ;
}
================================================== ===========================================
Bye
Guru Jois

May 28 '07 #7

P: n/a
Guru Jois wrote:
On May 28, 2:56 pm, Chief <blons...@gmail.comwrote:
>Hello i would like to know
which syntax do i have to use in order to make a program run other
*.exe program and also how to put inputs in it
<snip>
For command line program, Mr Carramba is right. But within a program,
try these stuffs

Your program, a parent process, forks a child and exec's the second
<snip>

Since most ".exe program"s are run on Windows and Windows does not have
fork or (last I looked) exec this advice is not likely to be too useful.

Doing anything beyond a call to system (and the OP probably wants more
than that) requires using system specific extensions and the best place
to ask about those is in system specific groups. so I suggest the OP ask
in a group dedicated to his implementation.
--
Flash Gordon
May 28 '07 #8

P: n/a
On May 28, 8:07 pm, Flash Gordon <s...@flash-gordon.me.ukwrote:
Guru Jois wrote:
On May 28, 2:56 pm, Chief <blons...@gmail.comwrote:
Hello i would like to know
which syntax do i have to use in order to make a program run other
*.exe program and also how to put inputs in it

<snip>
For command line program, Mr Carramba is right. But within a program,
try these stuffs
Your program, a parent process, forks a child and exec's the second

<snip>

Since most ".exe program"s are run on Windows and Windows does not have
fork or (last I looked) exec this advice is not likely to be too useful.

Doing anything beyond a call to system (and the OP probably wants more
than that) requires using system specific extensions and the best place
to ask about those is in system specific groups. so I suggest the OP ask
in a group dedicated to his implementation.
--
Flash Gordon
Ok, I agree to this. I got it now....bit later

Bye
Guru Jois

May 28 '07 #9

P: n/a

"Chief" <bl******@gmail.comwrote:
Hello i would like to know
which syntax do i have to use in order to make a program run other
*.exe program and also how to put inputs in it

for example i want to to make a program that run other file call
try.exe and save all the stdout into a file
Just write the whole command-line as a string, and feed the string to
the "system" function, like so:

#include <stdlib.h>
...
system("C:\\asdf\\try.exe 37 62 D:\\qwer\\output_file.txt");

That would look for a program called try.exe in folder C:\asdf,
feed it "37 62" as command-line arguments, and redirect the
output to file output_file.txt in folder D:\qwer.

That syntax should work for DOS or Windows. For Linux or Unix,
use / instead of \\. For other OSs, read the manual.

(In practice, with most compilers, you can use / instead of \\
even with DOS or Windows; the compiler translates. Look up
"system" in your compiler's manual.)
--
Cheers,
Robbie Hatley
East Tustin, CA, USA
lonewolf aatt well dott com
triple-dubya dott tustinfreezone dott org
May 28 '07 #10

P: n/a

"CBFalconer" wrote:
Chief wrote:

Hello i would like to know which syntax do i have to use in order
? to make a program run other *.exe program and also how to put
inputs in it. for example i want to to make a program that run
other file call try.exe and save all the stdout into a file

To start with you need an OS that can run .exe files.
*ALL* operating systems can run executable programs. That's what
they're for.
This is off-topic here.
No. It's a C-language question, with a C-language answer.
If you don't know the answer, it's better not to post a reply.
where we deal with the portable standard C language.
See section 7.20.4.6 of the standard for information on the
"system" function.
--
Cheers,
Robbie Hatley
East Tustin, CA, USA
lonewolf aatt well dott com
triple-dubya dott tustinfreezone dott org
May 28 '07 #11

P: n/a
On 28 May 2007 07:22:03 -0700, Guru Jois <gu*******@gmail.comwrote:
>On May 28, 2:56 pm, Chief <blons...@gmail.comwrote:
>Hello i would like to know
which syntax do i have to use in order to make a program run other
*.exe program and also how to put inputs in it

for example i want to to make a program that run other file call
try.exe and save all the stdout into a file

thanx

For command line program, Mr Carramba is right. But within a program,
try these stuffs

Your program, a parent process, forks a child and exec's the second
try.exe (with arguments). Close stdout for child and redirect its
output to a file using dup systemcall and pipes.
Fork is not a capability of standard C.
>
For more about fork() - see http://www.erlenstar.demon.co.uk/unix/faq_toc.html#TOC3
Even the url tells you it is unix unique. What makes you think the
original poster uses unix?
>
Here is a basic code that resembles your problem, though not same
This program pipes the o/p of 1 command to i/p of another
================================================= ===============================
#include<stdio.h>
main(){
int pfd[2] ;

if(pipe(pfd) < 0){
pipe is not a standard function.
> fprintf(stderr, "Cannot Create pipe\n");
exit(0);
}
switch(fork()){
fork is not a standard function.
> case -1:
fprintf(stderr, "cannot create child\n");
exit(-1);
case 0:
if(dup2(pfd[1] , 1 ) < 0){
dup2 is not a standard function.
> fprintf(stderr, "Cannot dup\n");
exit(0);
}
close(0) ;
close is not a standard function.
> close (pfd[1]);
close (pfd[0]);
execlp("ls", "ls", "-l", NULL) ;
execlp is not a standard function.
> fprintf(stderr, "Cannot exec 1\n");
default :
break ;
}
switch(fork()){
case -1:
fprintf(stderr, "Cannot fork 2\n");
exit(0);
case 0:
if(dup2(pfd[0] , 0) < 0) {
fprintf(stderr, "Cannot dup 2");
exit(0);
}
close(pfd[0]);
close(pfd[1]);
execl("/usr/bin/wc", "wc", NULL);
execl is not a standard function.
> fprintf(stderr, "Cannot exec 2\n");
default:
break ;
}
wait ((int *)0) ;
}
In this group, please try to confine your answers to on topic advice.
Remove del for email
May 28 '07 #12

P: n/a
Robbie Hatley wrote:
"CBFalconer" wrote:
>Chief wrote:
>>Hello i would like to know which syntax do i have to use in order
? to make a program run other *.exe program and also how to put
>>inputs in it. for example i want to to make a program that run
other file call try.exe and save all the stdout into a file
To start with you need an OS that can run .exe files.

*ALL* operating systems can run executable programs. That's what
they're for.
They can[1] run executable programs, but not necessarily a .exe
>This is off-topic here.

No. It's a C-language question, with a C-language answer.
If you don't know the answer, it's better not to post a reply.
>where we deal with the portable standard C language.

See section 7.20.4.6 of the standard for information on the
"system" function.
Which does not say how to redirect the output of the executed program.
It also does not provide a way to feed the program anything other than
command line arguments (assuming the OS supports them, which it probably
does) and I am not clear that the OP does not want to control what goes
to the programs standard input.

If Chuck only said what you quoted then I think he went too far, since
system *might* be sufficient to the OPs needs.

[1] I'm obviously excluding embedded OSs since they have different rules.
--
Flash Gordon
May 28 '07 #13

P: n/a
In article <tw*******************@fe06.news.easynews.com>,
Robbie Hatley <bo***********@no.spamwrote:
>"CBFalconer" wrote:
>Chief wrote:
Hello i would like to know which syntax do i have to use in order
? to make a program run other *.exe program
>To start with you need an OS that can run .exe files.
>*ALL* operating systems can run executable programs. That's what
they're for.
Even if "*ALL* operating systems can run executable programs"
(a statement that I would dispute), the question was not
about "executable programs": the question was about "other *.exe program".
CBFalconer is quite correct: in order to run a *.exe program,
you need an OS that can run .exe files. Most OS's cannot run
..exe files. A .exe file is a (small) family of file formats that
presumes a certain architecture; for example, the fundamental
..exe file header itself assumes that there are SS, SP, and IP registers.

By the way, the job of an operating system is to manage resources:
*That's* what they're for. There are a number of operating systems
that are perfectly capable of managing resources, and yet are not
able to load in executable programs. These operating systems tend
to be used for embedded systems.

>No. It's a C-language question, with a C-language answer.
If you don't know the answer, it's better not to post a reply.
>See section 7.20.4.6 of the standard for information on the
"system" function.
Including the section of the standard that indicates that there
is not necessarily any command interpreter available at all.
While you are there, notice that the standard says nothing about
requiring that system() be able to run executable programs,
only that it will interpret the given string in a system-dependant
way.
--
Okay, buzzwords only. Two syllables, tops. -- Laurie Anderson
May 28 '07 #14

P: n/a
Robbie Hatley wrote:
CBFalconer wrote:
>Chief wrote:
>>Hello i would like to know which syntax do i have to use in order
? to make a program run other *.exe program and also how to put
>>inputs in it. for example i want to to make a program that run
other file call try.exe and save all the stdout into a file

To start with you need an OS that can run .exe files.

*ALL* operating systems can run executable programs. That's what
they're for.
A .exe file is only an executable on some systems.
>
>This is off-topic here.

No. It's a C-language question, with a C-language answer.
If you don't know the answer, it's better not to post a reply.
Not so. An .exe file is specific to Windows/Dos (and maybe OS2).
It will not run under any circumstances on other machines (barring
a very specific interpreter).

--
<http://www.cs.auckland.ac.nz/~pgut001/pubs/vista_cost.txt>
<http://www.securityfocus.com/columnists/423>
<http://www.aaxnet.com/editor/edit043.html>
<http://kadaitcha.cx/vista/dogsbreakfast/index.html>
cbfalconer at maineline dot net

--
Posted via a free Usenet account from http://www.teranews.com

May 28 '07 #15

P: n/a
On 28 May 2007 04:52:50 -0700, "ad*************@gmail.com"
<ad*************@gmail.comwrote in comp.lang.c:
On 28 Maj, 13:36, Carramba <u...@example.netwrote:
Chief skrev:Hello i would like to know
which syntax do i have to use in order to make a program run other
*.exe program and also how to put inputs in it
for example i want to to make a program that run other file call
try.exe and save all the stdout into a file
thanx
I'm not sure what you mean, but this is my guess:

your_program.exe < input_file output_file

output_file ll contain same thing that you would see on your dos/shell
window

exec*() functions
There are no "exec*()" functions in the C library. If you are talking
about platform-specific non-standard extensions, they are off-topic
here.

--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://c-faq.com/
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++
http://www.club.cc.cmu.edu/~ajo/docs/FAQ-acllc.html
May 28 '07 #16

P: n/a
CBFalconer wrote:
It will not run under any circumstances on other machines (barring
a very specific interpreter).
Bah... I can name a number of environments (besides Windows, DOS and
OS/2), which are capable of running exe programs.

The exe image format, dates back to DOS, so any DOS clone like e.g.
*FreeDOS* (http://freedos.sourceforge.net/) or DR-DOS can do this too.
The DOS exe image format has 'MZ' signature (after Mark Zbikowski). With
Windows and OS/2 came the 'NE' format, and I think Windows NT introduced
the 'PE' format for Win32 programs. 'NE' and 'PE' are supersets of the
old 'MZ' exe format.

Here are some books I have on the subject:
The FreeDOS Kernel An MS-DOS emulator for platform independence and
embedded systems development

Undocumented DOS: a programmer's guide to reserved MS-DOS functions and
data structures Andrew Schulman, et. al. Addison-Wesley, 1990.

Windows Internals: The Implementation of the Windows Operating System,
Matt Pietrek, Addison-Wesley, 1993.

in particular, the "Undocumented DOS" was a very interesting read for a
young C programmer 15 years ago (ooops)..

I guess you had only *wine* (http://www.winehq.org) in mind, right? For
example, the commercial *Cedega*
http://www.transgaming.com/products_linux.php) and *ReactOS*
(www.reactos.org) should run 'PE' programs too.
--
Tor <torust [at] online [dot] no>
May 29 '07 #17

P: n/a
Tor Rustad wrote:
CBFalconer wrote:
>It will not run under any circumstances on other machines (barring
a very specific interpreter).

Bah... I can name a number of environments (besides Windows, DOS and
OS/2), which are capable of running exe programs.

The exe image format, dates back to DOS, so any DOS clone like e.g.
*FreeDOS* (http://freedos.sourceforge.net/) or DR-DOS can do this too.
The DOS exe image format has 'MZ' signature (after Mark Zbikowski). With
Windows and OS/2 came the 'NE' format, and I think Windows NT introduced
the 'PE' format for Win32 programs. 'NE' and 'PE' are supersets of the
old 'MZ' exe format.
RISC OS doesn't run any form of .exe file (unless you happen to
have a very specific interpreter or a PC card to hand).

--
The second Jena users conference -- be there or have rdf:type geometric:Square.

Hewlett-Packard Limited registered office: Cain Road, Bracknell,
registered no: 690597 England Berks RG12 1HN

May 29 '07 #18

P: n/a
Chris Dollin wrote:
RISC OS doesn't run any form of .exe file (unless you happen to
have a very specific interpreter or a PC card to hand).
What is a RISC OS?

FYI, Windows NT ran on RISC based platforms too, and came with a DOS
emulator.

--
Tor <torust [at] online [dot] no>
May 29 '07 #19

P: n/a
Tor Rustad said:
Chris Dollin wrote:
>RISC OS doesn't run any form of .exe file (unless you happen to
have a very specific interpreter or a PC card to hand).

What is a RISC OS?
http://www.riscos.com/

<snip>

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at the above domain, - www.
May 29 '07 #20

P: n/a
In article <Yt******************************@bt.com>,
Richard Heathfield <rj*@see.sig.invalidwrote:
>What is a RISC OS?
>http://www.riscos.com/
It was also the name of MIPS's System-V-based operating system

-- Richard
--
"Consideration shall be given to the need for as many as 32 characters
in some alphabets" - X3.4, 1963.
May 29 '07 #21

P: n/a
On May 28, 5:44 pm, Barry Schwarz <schwa...@doezl.netwrote:
On 28 May 2007 07:22:03 -0700, Guru Jois <guru.j...@gmail.comwrote:
Fork is not a capability of standard C.
For more about fork() - see http://www.erlenstar.demon.co.uk/unix/faq_toc.html#TOC3

Even the url tells you it is unix unique. What makes you think the
original poster uses unix?
I have a implementation of C which runs under DOS, and implements
fork. Charmingly, it implements it more or less like this:

int fork(void)
{
errno=ENOMEM;
return -1;
}

(I haven't seen the source code; this is my guess at what it does,
based on what I remember of the documentation. I can't remember
whether the return type is int or something else, but as it isn't a
standard C function it doesn't really matter.)

I find it hard to believe that this function could be used to run
a .exe file. It's also a good example to bear in mind that a function
with a name that isn't mentioned in the standard you're using can do
very different things on different implementations.
--
ais523

May 29 '07 #22

P: n/a
Richard Heathfield wrote:
Tor Rustad said:
>Chris Dollin wrote:
>>RISC OS doesn't run any form of .exe file (unless you happen to
have a very specific interpreter or a PC card to hand).
What is a RISC OS?

http://www.riscos.com/

<snip>
Without regard to RISC OS I remember NT development on MIPS way back
when. It was part of an initiative to replace IBM XT (and Intel) with a
more 'open' architecture. I don't know that NT ever ran on MIPS hardware.

--
Joe Wright
"Everything should be made as simple as possible, but not simpler."
--- Albert Einstein ---
May 29 '07 #23

P: n/a
In article <s7******************************@comcast.com>,
Joe Wright <jo********@comcast.netwrote:
>Without regard to RISC OS I remember NT development on MIPS way back
when. It was part of an initiative to replace IBM XT (and Intel) with a
more 'open' architecture. I don't know that NT ever ran on MIPS hardware.
<OT>
It did.

http://en.wikipedia.org/wiki/MIPS_Magnum

The early, R3000-based Magnum series ran only RISC/os, a variant
of BSD Unix, but the subsequent Magnum workstations based on the
Jazz architecture ran both RISC/os and Windows NT.
--
"No one has the right to destroy another person's belief by
demanding empirical evidence." -- Ann Landers
May 29 '07 #24

P: n/a
On Mon, 28 May 2007 16:07:01 +0100, in comp.lang.c , Flash Gordon
<sp**@flash-gordon.me.ukwrote:
>Since most ".exe program"s are run on Windows and Windows does not have
fork or (last I looked) exec this advice is not likely to be too useful.
A good example of why not to answer offtopically here. Both comments
above are wrong (unusually for Flash).

--
Mark McIntyre

"Debugging is twice as hard as writing the code in the first place.
Therefore, if you write the code as cleverly as possible, you are,
by definition, not smart enough to debug it."
--Brian Kernighan
May 29 '07 #25

P: n/a
On Tue, 29 May 2007 18:15:05 -0400, in comp.lang.c , Joe Wright
<jo********@comcast.netwrote:
>I don't know that NT ever ran on MIPS hardware.
It most certainly did. MS dropped support for the platform in 1996.
http://www.eetimes.com/news/96/924news/microsoft.html
--
Mark McIntyre

"Debugging is twice as hard as writing the code in the first place.
Therefore, if you write the code as cleverly as possible, you are,
by definition, not smart enough to debug it."
--Brian Kernighan
May 29 '07 #26

P: n/a
Mark McIntyre wrote, On 29/05/07 23:32:
On Mon, 28 May 2007 16:07:01 +0100, in comp.lang.c , Flash Gordon
<sp**@flash-gordon.me.ukwrote:
<snip>
A good example of why not to answer offtopically here. Both comments
above are wrong (unusually for Flash).
I don't mind being caught out sometimes if I have a reputation for not
normally being completely wrong :-)
--
Flash Gordon
Wishing I still had a company MSDN subscription so I could easily check
up on Windows information.
May 31 '07 #27

This discussion thread is closed

Replies have been disabled for this discussion.