• C

system()

Hello all,
I have a small doubt..
see this program:::

#include <stdlib.b>

void main()
{
system("type temp.c");
}



This will type the program BUT i want the parameter which executes the program.. PLzz help
Edit/Delete Message
hssumaAsked:
Who is Participating?
 
stuartdehaanConnect With a Mentor Commented:
Check this site
http://www.cplusplus.com/doc/compiler/vccl.html

if you add the referenced batch file to your autoexec.bat,
you only have to call
system("LC test.cpp");
which results in test.exe
0
 
PaulCaswellCommented:
Could you be asking for something like:

void main(int argc, char * argv[])
{
 int i;
 for ( i = 1; i <= argc; i++ ) system(argv[i]);
}

Paul
0
 
hssumaAuthor Commented:
No , i meant executing the program temp.c

system("type temp.c"); ... will only type the program i.e. temp.c on the console.. i want to execute the program temp.c ..
0
Firewall Management 201 with Professor Wool

In this whiteboard video, Professor Wool highlights the challenges, benefits and trade-offs of utilizing zero-touch automation for security policy change management. Watch and Learn!

 
PaulCaswellCommented:
system("temp.exe");

or just

system("temp");

or

system("\\TempFolder\\temp");

Executing 'system' is essentially like typing commands at the command prompt.

Paul
0
 
stuartdehaanCommented:
You have to compile the program first in order to execute temp.c.
Call for instance
cc.exe temp.c
to compile (or whatever the name of your compiler is).

Stuart
0
 
mactep13Commented:
Try execl instead of system. System is a volotile call, and is system (OS) specific. Using execl, you can execute a process:

#include <process.h>

execl("Temp.exe", "Temp.exe", NULL);

And you do need to compile the source and have an executable to run. Either use cc or gcc or other compilers. The most standard way to compile is:
gcc -o Temp.exe Temp.c

Hope this helps.

Mactep
0
 
hssumaAuthor Commented:

Now my 2nd program has to take i/p from the o/p of the first program.. i mean i do not have an executable file, i just have a program which i will have to compile, link and then execute.. In more simpler way, can't i have something like
  execl("temp.c",temp.c",NULL)    
 
Hope i was able to putforth my doubt/problem in understandable manner..

0
 
stuartdehaanCommented:
Yoo can several system calls (or execl); first compile,
system("gcc -o Temp.exe Temp.c");
than link,
system("link Temp.exe Temp.c");           <check the commandline, don't know your compiler>
than run,
system("temp");

Stuart
0
 
hssumaAuthor Commented:
Stuart, i think your comment shud work.. But can u tell me how can i compile and link my prog in command level in windows .. I'm using VC++ as the environment to run my C programs..
0
 
hssumaAuthor Commented:
Hello,
    The command to compile and link a C-program is CL and not LC... Similarly i tried to look out for the command to compile and linka matlab program.. i get an error

Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 12.00.8168 for 80x86
Copyright (C) Microsoft Corp 1984-1998. All rights reserved.

Command line warning D4024 : unrecognized source file type 'd:\su_mat\temp.m', object file ass
umed
Microsoft (R) Incremental Linker Version 6.00.8168
Copyright (C) Microsoft Corp 1992-1998. All rights reserved.

/out:temp.exe
d:\su_mat\temp.m
d:\su_mat\temp.m : fatal error LNK1136: invalid or corrupt file
'temp.exe' is not recognized as an internal or external command,
operable program or batch file.
Press any key to continue


When i run the same program in matlab, it works...


Please help me..
0
 
stuartdehaanCommented:
You're right with lc, I copy-pasted that from the site.
I'm not sure what the temp.m file is, but you should use .c or .cpp files with cl.

Stuart
0
 
hssumaAuthor Commented:
Ya, CL works for only .c an d.cpp files... ANybody working on matlab plzz help me in finding the cmd to compila and link .m files..

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.