29. november 1999 - 17:06Der er
4 kommentarer og 1 løsning
afvikling af cmd fra C prg i NT 4.0
i C til dos findes der en kommando(system) som afvikler et andet program. Nu står jeg så i den bizare situation at skulle lave et C program til NT4.0 - er der en kommando i C til dos som kan anvendes ligesom system ?
Nu kender jeg ikke NT, men hvorfor kan du ikke bruge system()?
Ellers er her nogle andre funktioner - aner ikke om du kan bruge dem...
# spawn... functions
The spawn... functions let your program run other files (child processes) and return control to your program when those processes finish.
Prototype in process.h
Use these spawn... functions when you know how many separate arguments you'll have:
int spawnl(int mode, char *path, char *arg0, ..., NULL); int spawnle(int mode, char *path, char *arg0, ..., NULL, char *envp[]); int spawnlp(int mode, char *path, char *arg0, ..., NULL); int spawnlpe(int mode, char *path, char *arg0, ..., NULL, char *envp[]);
These spawn... functions are used when you don't know in advance how many separate arguments you will have:
int spawnv(int mode, char *path, char *argv[]); int spawnve(int mode, char *path, char *argv[], char *envp[]); int spawnvp(int mode, char *path, char *argv[]); int spawnvpe(int mode, char *path, char *argv[], char *envp[]);
The letters at the end of each spawn... function identify which variation is used:
Ltr Variation used ÍÍÍÍÍÍØÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ p ³ search the DOS path for child l ³ spawn passed a fixed list of args v ³ spawn passed a variable list of args e ³ spawn passes an envp ptr, allowing ³ you to alter the environment the ³ child will have
On a successful execution, the return value is the child process's exit status (0 for normal termination). If the child specifically calls exit with a nonzero argument, its exit status can be set to a nonzero value.
If the process can't be spawn...ed successfully, the spawn... functions will return -1.
# exec... functions
The exec... functions let your program run other files (child processes).
When an exec... call succeeds, the child process overlays the parent process. There must be sufficient memory available for loading and executing the child process.
Prototype in process.h
Use these exec... functions when you know how many separate arguments you'll have:
int execl(char *path, char *arg0, .., NULL); int execle(char *path, char *arg0, .., NULL, char **env); int execlp(char *path, char *arg0, ..); int execlpe(char *path, char *arg0, .., NULL, char **env);
These exec... functions are used when you don't know in advance how many separate arguments you will have:
int execv(char *path, char *argv[]); int execve(char *path, char *argv[], char **env); int execvp(char *path, char *argv[]); int execvpe(char *path, char *argv[], char **env);
The letters at the end of each exec... function identify which variation is used:
Ltr ³ Variation used ÍÍÍÍÍÍØÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ p ³ search the DOS path for child ³ l ³ exec passed a fixed list of args ³ v ³ exec passed a variable list of args ³ e ³ exec passes an envp ptr, allowing ³ you to alter the environment the ³ child will have
If successful, the exec functions do not return. On error, the exec functions return -1 and set errno.
bjarke >> ehh - jeg har fundet ud af at hvis jeg afvikler .exe filen er alles gut. Det er nær jeg vil debugge det gør galt - der sker der ingenting. Jeg har oplevet det får hvor jeg ville øndre mode con via system...
CreateProcess() er den egentlige funktion hvis du skal bruge rent Win32.
Hvis du er mere til crossplatform, vil jeg foreslå system() kaldet som starter en os-shell.
En os-shell er i windows afhængig af extension så hvis du skriver system("http://www.mindpass.com/") vil dette launche din browser.
Synes godt om
Ny brugerNybegynder
Din løsning...
Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.