LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   ShellExecute C (https://www.linuxquestions.org/questions/linux-software-2/shellexecute-c-47500/)

Canadian_2k2 02-27-2003 07:58 PM

ShellExecute C
 
What is the syntax to run a program in C?
I want my C program to execute another program
I am a noob at C/C++ programming,
My friend said something about
ShellExecute(handle, NULL, path_to_folder, NULL, NULL, SW_SHOWNORMAL)

But I don't know what that is... how would I execute a program
named hi ???

Thanx
--
Canadian Daemon

Tinkster 02-27-2003 08:03 PM

Do a search for exec in the programming forum :)
Or a man system.

Cheers,
Tink

Crashed_Again 02-27-2003 08:36 PM

Well its been a while since college but aren't C programs just executables? If so you would just do:

./hi

if the C programs name was hi.

Canadian_2k2 02-27-2003 09:39 PM

Ya, but in my other program, what is the syntax to execute another program... do i go..
int main()
{
cin >> programname;
./programname
}

????

Crashed_Again 02-27-2003 09:44 PM

Oh you mean in the source code itself? This is a programming question right? Ummm...well I'm no c programming expert but I do remember a function that might work for this.

int ok;

int main()
{
ok=system("programname")
}

I'm not sure if thats the exact syntax but I know the system function passes the argument directly to the command line.

Canadian_2k2 02-28-2003 12:00 AM

Thanx, what header is that in?
When I compile my program, I geth
hi.c: In function `int main()':
hi.c:11: `ok' undeclared (first use this function)
hi.c:11: (Each undeclared identifier is reported only once for each function it
appears in.)

#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

#include <iostream.h>
#include <stdlib.h>
#include <shellapi.h>

int main()
{
ok =system("emacs");


return EXIT_SUCCESS;
}




Thanx

Crashed_Again 02-28-2003 07:41 AM

I think it is in

#include <stdio.h>

Canadian_2k2 03-03-2003 07:28 PM

Thanx
I didn't need the ok= though,

Thanx for the help


All times are GMT -5. The time now is 11:00 AM.