LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 02-27-2003, 08:58 PM   #1
Canadian_2k2
Member
 
Registered: Oct 2002
Location: BC,Canada
Distribution: Debian
Posts: 92

Rep: Reputation: 15
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
 
Old 02-27-2003, 09:03 PM   #2
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,066
Blog Entries: 11

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

Cheers,
Tink
 
Old 02-27-2003, 09:36 PM   #3
Crashed_Again
Senior Member
 
Registered: Dec 2002
Location: Atlantic City, NJ
Distribution: Ubuntu & Arch
Posts: 3,503

Rep: Reputation: 57
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.
 
Old 02-27-2003, 10:39 PM   #4
Canadian_2k2
Member
 
Registered: Oct 2002
Location: BC,Canada
Distribution: Debian
Posts: 92

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

????
 
Old 02-27-2003, 10:44 PM   #5
Crashed_Again
Senior Member
 
Registered: Dec 2002
Location: Atlantic City, NJ
Distribution: Ubuntu & Arch
Posts: 3,503

Rep: Reputation: 57
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.
 
Old 02-28-2003, 01:00 AM   #6
Canadian_2k2
Member
 
Registered: Oct 2002
Location: BC,Canada
Distribution: Debian
Posts: 92

Original Poster
Rep: Reputation: 15
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
 
Old 02-28-2003, 08:41 AM   #7
Crashed_Again
Senior Member
 
Registered: Dec 2002
Location: Atlantic City, NJ
Distribution: Ubuntu & Arch
Posts: 3,503

Rep: Reputation: 57
I think it is in

#include <stdio.h>
 
Old 03-03-2003, 08:28 PM   #8
Canadian_2k2
Member
 
Registered: Oct 2002
Location: BC,Canada
Distribution: Debian
Posts: 92

Original Poster
Rep: Reputation: 15
Thanx
I didn't need the ok= though,

Thanx for the help
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Is there something like ShellExecute in linux?? cppkid Programming 4 08-06-2004 03:15 AM


All times are GMT -5. The time now is 02:57 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration