Home     |     .Net Programming    |     cSharp Home    |     Sql Server Home    |     Javascript / Client Side Development     |     Ajax Programming

Ruby on Rails Development     |     Perl Programming     |     C Programming Language     |     C++ Programming     |     IT Jobs

Python Programming Language     |     Laptop Suggestions?    |     TCL Scripting     |     Fortran Programming     |     Scheme Programming Language


 
 
Cervo Technologies
The Right Source to Outsource

MS Dynamics CRM 3.0

C Programming Language

How do i Run programs


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

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

On 28 Maj, 13:36, Carramba <u@example.net> wrote:

> 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
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

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.

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>

On May 28, 2:56 pm, Chief <blons@gmail.com> 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

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

Guru Jois wrote:
> On May 28, 2:56 pm, Chief <blons@gmail.com> 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

<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

"Chief" <blons@gmail.com> 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

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

"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

On 28 May 2007 07:22:03 -0700, Guru Jois <guru.j@gmail.com> wrote:

Fork is not a capability of standard C.

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.

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

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

In article <twD6i.527609$9i2.2@fe06.news.easynews.com>,

Robbie Hatley <bogus.addr@no.spam> 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
>> 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

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

On 28 May 2007 04:52:50 -0700, "adam.wieckow@gmail.com"
<adam.wieckow@gmail.com> wrote in comp.lang.c:

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

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>

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

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>

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.

In article <YtudnSRTjfFZo8HbnZ2dnUVZ8vqdn@bt.com>,
Richard Heathfield  <r@see.sig.invalid> wrote:

>> 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.

On May 28, 5:44 pm, Barry Schwarz <schwa@doezl.net> wrote:

> On 28 May 2007 07:22:03 -0700, Guru Jois <guru.j@gmail.com> wrote:
> 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

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 ---

In article <s7udnYUuHdB0OMHbnZ2dnUVZ_oKnn@comcast.com>,
Joe Wright  <joewwri@comcast.net> wrote:

>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

On Mon, 28 May 2007 16:07:01 +0100, in comp.lang.c , Flash Gordon

<s@flash-gordon.me.uk> wrote:
>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

Add to del.icio.us | Digg this | Stumble it | Powered by Megasolutions Inc