run external executable

how to run an external executable

Page 1 of 1

11 Replies - 218237 Views - Last Post: 20 October 2009 - 03:36 AM Rate Topic: -----

#1 steph22  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 24-August 06

run external executable

Posted 24 August 2006 - 02:42 PM

Hi,
I'm trying to run a .exe file from a .c file. I've been looking at previous posts, and saw that one option was using this command:

Process.Start("c:\myTestFolder\myfile.exe")


However, I'm having trouble getting this to work. What type of libraries/sources do I need to include? and how do I initialize process and start?

what I'm hoping to have is

if(x=1){
   "run program"
}


Thanks for any help,
steph

This post has been edited by Dark_Nexus: 24 August 2006 - 03:15 PM


Is This A Good Question/Topic? 0
  • +

Replies To: run external executable

#2 help-linux  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 3
  • View blog
  • Posts: 54
  • Joined: 12-August 06

Re: run external executable

Posted 24 August 2006 - 05:27 PM

if you want to do it on windows, use "system("my_exe.exe");" with windows.h included

on linux you need to do: "system("./my_bin.bin");"

i think the linux one with work on both i am not sure
Was This Post Helpful? 0
  • +
  • -

#3 Jayman  Icon User is offline

  • Student of Life
  • member icon

Reputation: 421
  • View blog
  • Posts: 9,532
  • Joined: 26-December 05

Re: run external executable

Posted 24 August 2006 - 07:31 PM

View Poststeph22, on 24 Aug, 2006 - 02:42 PM, said:

Process.Start("c:\myTestFolder\myfile.exe")

That is for VB.NET, use the system command as previous posted if on windows.

This post has been edited by jayman9: 24 August 2006 - 07:32 PM

Was This Post Helpful? 0
  • +
  • -

#7 DeeViLiSh  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 6
  • View blog
  • Posts: 175
  • Joined: 25-July 06

Re: run external executable

Posted 24 August 2006 - 11:05 PM

Hmm... lol.

#include<stdlib.h> or #include <windows.h>

system("start c:\\Documents And Settings\\Me\\wow.exe");



Use \\ instead of \ in your compiler.

PS : The principe of the system(" ... "); is the same thing as going in Start>Run>cmd. It's the Command Module for windows. You enter in the " ... " what you'd type in the console. for example to check disk system("CHKDSK C:\\");

EDIT 2 : Oops, it works with windows.h as header instead of stdlib.h so both are fine.

EDIT: Added code tags

This post has been edited by Dark_Nexus: 29 October 2006 - 11:48 AM

Was This Post Helpful? 1

#8 born2c0de  Icon User is offline

  • printf("I'm a %XR",195936478);
  • member icon

Reputation: 187
  • View blog
  • Posts: 4,673
  • Joined: 26-November 04

Re: run external executable

Posted 25 August 2006 - 03:34 AM

Avoid using system() function calls when there is an API Function available.
You can use it like this:
ShellExecute(GetDesktopWindow(), "open", "c:\myTestFolder\myfile.exe", NULL, NULL, SW_SHOWNORMAL);


You'll have to include windows.h to use this.
Was This Post Helpful? 1

#9 steph22  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 24-August 06

Re: run external executable

Posted 25 August 2006 - 07:12 AM

Wow... thanks for all the help.
the system("myfile.exe"); works great for normal compilation. However, I forgot to mention this :( I'm trying to compile using WinCon in Matlab. I don't know if any of you have any suggestions.
also... does anyone know what needs to be included to use

ShellExecute(GetDesktopWindow(), "open", "c:\myTestFolder\myfile.exe", NULL, NULL, SW_SHOWNORMAL);


These are the errors I'mgetting when I try to compile

Quote

executable.obj : error LNK2001: unresolved external symbol [email protected]
executable.obj : error LNK2001: unresolved external symbol [email protected]
executable.dll : fatal error LNK1120: 2 unresolved externals


Thanks again,
Steph

This post has been edited by Dark_Nexus: 25 August 2006 - 08:32 AM

Was This Post Helpful? 0
  • +
  • -

#10 steph22  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 24-August 06

Re: run external executable

Posted 25 August 2006 - 07:34 AM

just found - FYI

"because the real-time code is executed in a (WinCon) real-time kernel environment (essentially an operating
system buried underneath Windows), Windows operating system functions cannot be called."

If anyone has any other suggestions, please let me know.

Thanks,
Steph
Was This Post Helpful? 0
  • +
  • -

#11 help-linux  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 3
  • View blog
  • Posts: 54
  • Joined: 12-August 06

Re: run external executable

Posted 25 August 2006 - 08:39 AM

you need to include a lib file, i dont know what it is but i would first try user32.lib or kernel32.lib

EDIT: sorry i didn't mean "include" i ment "link against"

This post has been edited by help-linux: 25 August 2006 - 08:40 AM

Was This Post Helpful? 0
  • +
  • -

#12 nelsinho  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 27-October 06

Re: run external executable

Posted 27 October 2006 - 08:31 AM

View Postborn2c0de, on 25 Aug, 2006 - 03:34 AM, said:

Avoid using system() function calls when there is an API Function available.
You can use it like this:
ShellExecute(GetDesktopWindow(), "open", "c:\myTestFolder\myfile.exe", NULL, NULL, SW_SHOWNORMAL);


You'll have to include windows.h to use this.


Hi, this is my first post.

Im using ShellExecute to execute external programs, now my application needs to run on Linux, does ShellExecute "run linux external programs"?.

Thx
../Nelsinho

PS: Sorry my engliss
Was This Post Helpful? 0
  • +
  • -

#13 gregoryH  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 60
  • View blog
  • Posts: 656
  • Joined: 04-October 06

Re: run external executable

Posted 29 October 2006 - 06:31 AM

View Postnelsinho, on 27 Oct, 2006 - 08:31 AM, said:

View Postborn2c0de, on 25 Aug, 2006 - 03:34 AM, said:

Avoid using system() function calls when there is an API Function available.
You can use it like this:
ShellExecute(GetDesktopWindow(), "open", "c:\myTestFolder\myfile.exe", NULL, NULL, SW_SHOWNORMAL);


You'll have to include windows.h to use this.


Hi, this is my first post.

Im using ShellExecute to execute external programs, now my application needs to run on Linux, does ShellExecute "run linux external programs"?.

Thx
../Nelsinho

PS: Sorry my engliss


Short answer here - no.. inux and WIN32 API are not the same and code is not portable. I seem to recall that on *nix its fork or forkprocess
Was This Post Helpful? 0
  • +
  • -

#14 polymath  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 53
  • View blog
  • Posts: 670
  • Joined: 04-April 08

Re: run external executable

Posted 20 April 2008 - 11:46 AM

is it possible to use a variable in to run (for example): C:\%variable%\file.extension?

and can you open folders (eg C:\Documents and Settings\All Users\Shared Documents)?

thx
Was This Post Helpful? 0
  • +
  • -

#15 liquidpaper  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 24-May 09

Re: run external executable

Posted 20 October 2009 - 03:36 AM

View Postpolymath, on 20 Apr, 2008 - 10:46 AM, said:

and can you open folders (eg C:\Documents and Settings\All Users\Shared Documents)?


i'm not sure if you can just give shellexecute just a plain folder to open it but in the case that you can't you can simply run explorer.exe with the folder as the argument that you want to open e.g.

ShellExecute(GetDesktopWindow(), "open", "explorer.exe", "\"c:\\windows\\\"", NULL, SW_SHOWNORMAL);



Quote

Im using ShellExecute to execute external programs, now my application needs to run on Linux, does ShellExecute "run linux external programs"?.


you can always run your program with wine but when writing programs that you will want to compile on Linux AND windows use the preprocessor to use a different function if the desired function is not avaliable on Linux e.g.

#ifdef "windows specific macro"
ShellExecute(parameters);
#else //ifndef
system(command);
#endif



or simply use the preprocessor to define shellexecute if the compiling environment is linux. e.g.

#ifndef "windows specific macro"
#define ShellExecute "Linux equivalent"
#endif



If no linux equivalent exists you can make your own linux equivalent in the program and have it just pass the command line of the function to system. e.g.

#define ShellExecute my_linux_shellexecute
void my_linux_shellexecute(string cmd, string arg)
{
	   system(cmd+arg);
}




just as a basic example
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1