mirror of
https://github.com/reactos/reactos.git
synced 2025-07-12 13:44:14 +00:00
start (to detach a new process) and kill commands added
svn path=/trunk/; revision=535
This commit is contained in:
parent
f298282475
commit
154db698c9
1 changed files with 139 additions and 26 deletions
|
@ -2,6 +2,7 @@
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
|
|
||||||
|
|
||||||
|
@ -20,7 +21,11 @@ void debug_printf(char* fmt, ...)
|
||||||
|
|
||||||
void ExecuteVer(void)
|
void ExecuteVer(void)
|
||||||
{
|
{
|
||||||
debug_printf("Reactos Simple Shell\n");
|
debug_printf(
|
||||||
|
"Reactos Simple Shell\n(compiled on %s, at %s)\n",
|
||||||
|
__DATE__,
|
||||||
|
__TIME__
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ExecuteCd(char* cmdline)
|
void ExecuteCd(char* cmdline)
|
||||||
|
@ -96,33 +101,131 @@ void ExecuteType(char* cmdline)
|
||||||
CloseHandle(FileHandle);
|
CloseHandle(FileHandle);
|
||||||
}
|
}
|
||||||
|
|
||||||
int ExecuteProcess(char* name, char* cmdline)
|
int ExecuteProcess(char* name, char* cmdline, BOOL detached)
|
||||||
{
|
{
|
||||||
PROCESS_INFORMATION ProcessInformation;
|
PROCESS_INFORMATION ProcessInformation;
|
||||||
STARTUPINFO StartupInfo;
|
STARTUPINFO StartupInfo;
|
||||||
// char arguments;
|
// char arguments;
|
||||||
BOOL ret;
|
BOOL ret;
|
||||||
|
|
||||||
memset(&StartupInfo,0,sizeof(StartupInfo));
|
memset(
|
||||||
StartupInfo.cb = sizeof(STARTUPINFO);
|
& StartupInfo,
|
||||||
StartupInfo.lpTitle = name;
|
0,
|
||||||
|
(sizeof StartupInfo)
|
||||||
|
);
|
||||||
|
StartupInfo.cb = sizeof (STARTUPINFO);
|
||||||
|
StartupInfo.lpTitle = name;
|
||||||
|
|
||||||
ret = CreateProcessA(name,
|
ret = CreateProcessA(
|
||||||
cmdline,
|
name,
|
||||||
NULL,
|
cmdline,
|
||||||
NULL,
|
NULL,
|
||||||
TRUE,
|
NULL,
|
||||||
CREATE_NEW_CONSOLE,
|
TRUE,
|
||||||
NULL,
|
( (TRUE == detached)
|
||||||
NULL,
|
? DETACHED_PROCESS
|
||||||
&StartupInfo,
|
: CREATE_NEW_CONSOLE
|
||||||
&ProcessInformation);
|
),
|
||||||
if (ret)
|
NULL,
|
||||||
{
|
NULL,
|
||||||
WaitForSingleObject(ProcessInformation.hProcess,INFINITE);
|
& StartupInfo,
|
||||||
}
|
& ProcessInformation
|
||||||
CloseHandle(ProcessInformation.hProcess);
|
);
|
||||||
return(ret);
|
if (TRUE == detached)
|
||||||
|
{
|
||||||
|
if (ret)
|
||||||
|
{
|
||||||
|
debug_printf(
|
||||||
|
"%s detached:\n\
|
||||||
|
\thProcess = %08X\n\
|
||||||
|
\thThread = %08X\n\
|
||||||
|
\tPID = %d\n\
|
||||||
|
\tTID = %d\n\n",
|
||||||
|
ProcessInformation.hProcess,
|
||||||
|
ProcessInformation.hThread,
|
||||||
|
ProcessInformation.dwProcessId,
|
||||||
|
ProcessInformation.dwThreadId
|
||||||
|
);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
debug_printf("Could not detach %s\n");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (ret)
|
||||||
|
{
|
||||||
|
WaitForSingleObject(
|
||||||
|
ProcessInformation.hProcess,
|
||||||
|
INFINITE
|
||||||
|
);
|
||||||
|
}
|
||||||
|
CloseHandle(ProcessInformation.hProcess);
|
||||||
|
}
|
||||||
|
return(ret);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
ExecuteStart(
|
||||||
|
char * CommandLine
|
||||||
|
)
|
||||||
|
{
|
||||||
|
char *ImageName = CommandLine;
|
||||||
|
|
||||||
|
for ( ;
|
||||||
|
( (*CommandLine)
|
||||||
|
&& (*CommandLine != ' ')
|
||||||
|
&& (*CommandLine != '\t')
|
||||||
|
);
|
||||||
|
CommandLine++
|
||||||
|
);
|
||||||
|
*CommandLine++ = '\0';
|
||||||
|
while ( (*CommandLine)
|
||||||
|
&& ( (*CommandLine == ' ')
|
||||||
|
|| (*CommandLine == '\t')
|
||||||
|
)
|
||||||
|
);
|
||||||
|
ExecuteProcess(
|
||||||
|
ImageName,
|
||||||
|
CommandLine,
|
||||||
|
TRUE
|
||||||
|
);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
ExecuteKill(char * lpPid)
|
||||||
|
{
|
||||||
|
HANDLE hProcess;
|
||||||
|
DWORD dwProcessId;
|
||||||
|
|
||||||
|
dwProcessId = (DWORD) atol(lpPid);
|
||||||
|
hProcess = OpenProcess(
|
||||||
|
PROCESS_TERMINATE,
|
||||||
|
FALSE,
|
||||||
|
dwProcessId
|
||||||
|
);
|
||||||
|
if (NULL == hProcess)
|
||||||
|
{
|
||||||
|
debug_printf(
|
||||||
|
"Could not open the process with PID = %d\n",
|
||||||
|
dwProcessId
|
||||||
|
);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (FALSE == TerminateProcess(
|
||||||
|
hProcess,
|
||||||
|
0
|
||||||
|
)
|
||||||
|
) {
|
||||||
|
debug_printf(
|
||||||
|
"Could not terminate the process with PID = %d\n",
|
||||||
|
dwProcessId
|
||||||
|
);
|
||||||
|
}
|
||||||
|
CloseHandle(hProcess);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ExecuteCommand(char* line)
|
void ExecuteCommand(char* line)
|
||||||
|
@ -165,6 +268,11 @@ void ExecuteCommand(char* line)
|
||||||
ExecuteDir(tail);
|
ExecuteDir(tail);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if (strcmp(cmd,"kill")==0)
|
||||||
|
{
|
||||||
|
ExecuteKill(tail);
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (strcmp(cmd,"type")==0)
|
if (strcmp(cmd,"type")==0)
|
||||||
{
|
{
|
||||||
ExecuteType(tail);
|
ExecuteType(tail);
|
||||||
|
@ -188,12 +296,17 @@ void ExecuteCommand(char* line)
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if (strcmp(cmd,"start") == 0)
|
||||||
|
{
|
||||||
|
ExecuteStart(tail);
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (strcmp(cmd,"exit")==0)
|
if (strcmp(cmd,"exit")==0)
|
||||||
{
|
{
|
||||||
ExitProcess(0);
|
ExitProcess(0);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (ExecuteProcess(cmd,tail))
|
if (ExecuteProcess(cmd,tail,FALSE))
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue