Welcome to Dream.In.Code
Become a C++ Expert!

Join 149,550 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 1,564 people online right now. Registration is fast and FREE... Join Now!




Calling a program within C++

 
Reply to this topicStart new topic

Calling a program within C++, hmm

mattman059
20 Nov, 2007 - 05:14 PM
Post #1

D.I.C Regular
Group Icon

Joined: 23 Oct, 2006
Posts: 361


Dream Kudos: 175
My Contributions
So, I'm writting a program that will call another program that i've already written and im getting some unexpected results when I compile..heres what i've got

CODE

#include <iostream>
#include <fstream>

using namespace std;

int main()
{

   system("create_file.exe");


    ...random other stuff....
     cout << "DONE" << endl;

    return 0;
}


I thought that you could use system() with program calls..but i guess i'm just not sure how to use it. This is the error i get upon compiling and executing

QUOTE

'create_file.exe' is not recognized as an internal or external command, operable program or batch file.


Any ideas on how to fix this?
User is offlineProfile CardPM
+Quote Post

jjhaag
RE: Calling A Program Within C++
20 Nov, 2007 - 05:54 PM
Post #2

me editor am smartastic
Group Icon

Joined: 18 Sep, 2007
Posts: 1,789



Thanked: 2 times
Dream Kudos: 775
Expert In: C,C++

My Contributions
Well, you can definitely use system() for making system calls. It passes the string argument to the command processor, which then executes it.

However, create_file.exe is not a standard command on any system that I am aware of. This would only work if you already have a program named "create_file.exe" that is on the path of the command processor, and that error is telling you that this is not the case. Have you created this executable somewhere? And what exactly is this call supposed to do?

User is offlineProfile CardPM
+Quote Post

mattman059
RE: Calling A Program Within C++
21 Nov, 2007 - 06:10 PM
Post #3

D.I.C Regular
Group Icon

Joined: 23 Oct, 2006
Posts: 361


Dream Kudos: 175
My Contributions
create_file.exe was a c++ program that I wrote to basically create a file, insert a value then close. I created a shortcut for the EXE on my desktop. so do i need to include the path to my desktop in the call for create_file?

Thanks
User is offlineProfile CardPM
+Quote Post

Amadeus
RE: Calling A Program Within C++
21 Nov, 2007 - 06:13 PM
Post #4

g++ -o drink whiskey.cpp
Group Icon

Joined: 12 Jul, 2002
Posts: 12,349



Thanked: 51 times
Dream Kudos: 25
My Contributions
The system call should include the path to the executable, not the shortcut. Unless, of course, the executable is already in the same directory as the calling program.
User is offlineProfile CardPM
+Quote Post

mattman059
RE: Calling A Program Within C++
21 Nov, 2007 - 06:19 PM
Post #5

D.I.C Regular
Group Icon

Joined: 23 Oct, 2006
Posts: 361


Dream Kudos: 175
My Contributions
perfect! icon_up.gif thanks Amadeus.
User is offlineProfile CardPM
+Quote Post

Reply to this topicStart new topic
Time is now: 1/7/09 09:43PM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month