PROCESS CREATION IN WIN32 #include <stdio.h> #include <windows.h> int main(VOID) STARTUPINFO si; PROCESS_INFORMATION pi; /allocate merory ZeroMemory(si,sizeof(si)); si.cb sizeof(si); ZeroMemory(pi,sizeof(pi)); /create child process if (ICreateProcess(NULL,/use command line "C:\\WINDOWS\\system32\\mspaint.exe",/command line NULL,/don't inherit process handle NULL,/don't inherit thread handle FALSE,/disable handle inheritance 0,/no creation flags NULL,/use parent's environment block NULL,/use parent's existing directory 51, 卸i)) fprintf(stderr,"Create Process Failed"); return -1; /parent will vait for the child to complete WaitForSingleObject(pi.hProcess,INFINITE); printf("Child Complete"); /close handles CloseHandle(pi.hProcess); CloseHandle(pi.hThread);
PROCESS CREATION IN WIN32
PROCESS CREATION IN JAVA import java.io.*i public class OSProcess public static void main(String[]args)throws IOException if (args.length !1){ System.err.println("Usage:java OSProcess <command>"); System.exit(0); /∥args[o】is the command ProcessBuilder pb nev ProcessBuilder(args[O]); Process proc pb.start(); /obtain the input stream InputStream is proc.getInputStream(); InputStreamReader isr new InputStreamReader(is); BufferedReader br new BufferedReader(isr); /read what is returned by the command String line; while (line br.readLine())!null) System.out.println(line); br.close();
PROCESS CREATION IN JAVA