1 | #include <os2safe.h>
|
---|
2 | #define INCL_DOS
|
---|
3 | #define INCL_DOSERRORS
|
---|
4 | #include <os2.h>
|
---|
5 |
|
---|
6 | #include <stdio.h>
|
---|
7 | #include <stdlib.h>
|
---|
8 | #include <string.h>
|
---|
9 |
|
---|
10 | int main(VOID) {
|
---|
11 | STARTDATA sd = {0};
|
---|
12 | PSZ exePath = "CMD.EXE";
|
---|
13 | PSZ args = "/K";
|
---|
14 | APIRET rc = NO_ERROR; /* Return code */
|
---|
15 | PID pid = 0; /* PID returned */
|
---|
16 | ULONG ulSessID = 0; /* Session ID returned */
|
---|
17 | PCHAR env, pchEnvLast;
|
---|
18 | LONG lEnvSize, lNewEnvSize;
|
---|
19 | PPIB ppib;
|
---|
20 |
|
---|
21 | DosGetInfoBlocks( NULL, &ppib );
|
---|
22 | pchEnvLast = ppib->pib_pchenv;
|
---|
23 | while( *pchEnvLast )
|
---|
24 | pchEnvLast += strlen( pchEnvLast ) + 1;
|
---|
25 |
|
---|
26 | lEnvSize = pchEnvLast - ppib->pib_pchenv;
|
---|
27 | lNewEnvSize = lEnvSize + 100;
|
---|
28 | env = malloc( lNewEnvSize );
|
---|
29 | memset( env, 0, lNewEnvSize );
|
---|
30 | memcpy( env, ppib->pib_pchenv, lEnvSize );
|
---|
31 | strcpy( env + lEnvSize, "PETER=Weilbacher");
|
---|
32 |
|
---|
33 | sd.Length = 60; // fill everything
|
---|
34 | sd.PgmName = exePath; // the executable
|
---|
35 | sd.PgmInputs = args; // the arguments (without the program name)
|
---|
36 | sd.Environment = env;
|
---|
37 |
|
---|
38 | rc = DosStartSession(&sd, &ulSessID, &pid); /* Start the session */
|
---|
39 |
|
---|
40 | free( env );
|
---|
41 |
|
---|
42 | if (rc != NO_ERROR) {
|
---|
43 | printf ("DosStartSession error : return code = %u\n", rc);
|
---|
44 | return 1;
|
---|
45 | }
|
---|
46 |
|
---|
47 | return NO_ERROR;
|
---|
48 | }
|
---|