1. Switch CommandLauncher from a console application to a windows application so that no windows pop up during install.
2. Handle spaces in files names.
This commit is contained in:
@@ -1,136 +0,0 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <conio.h>
|
||||
#include <process.h>
|
||||
#include <errno.h>
|
||||
|
||||
#define ERROR_NO_ERROR 0
|
||||
#define ERROR_MEMORY_ALLOCATION_FAILED -1
|
||||
#define ERROR_INVALID_NUMBER_OF_PARAMETERS -2
|
||||
#define ERROR_EXEC_E2BIG -3
|
||||
#define ERROR_EXEC_EACCES -4
|
||||
#define ERROR_EXEC_EINVAL -5
|
||||
#define ERROR_EXEC_EMFILE -6
|
||||
#define ERROR_EXEC_ENOENT -7
|
||||
#define ERROR_EXEC_ENOEXEC -8
|
||||
#define ERROR_EXEC_ENOMEM -9
|
||||
#define ERROR_EXEC_UNKNOWN -10
|
||||
|
||||
|
||||
char * errorMessage(int err)
|
||||
{
|
||||
switch (err)
|
||||
{
|
||||
case ERROR_NO_ERROR:
|
||||
return "No error\n";
|
||||
case ERROR_MEMORY_ALLOCATION_FAILED:
|
||||
return "Memory allocation failed\n";
|
||||
case ERROR_INVALID_NUMBER_OF_PARAMETERS:
|
||||
return "Invalid number of parameters\n";
|
||||
case ERROR_EXEC_E2BIG:
|
||||
return "_exec: The space required for the arguments and environment settings exceeds 32 KB.\n";
|
||||
case ERROR_EXEC_EACCES:
|
||||
return "_exec: The specified file has a locking or sharing violation.\n";
|
||||
case ERROR_EXEC_EINVAL:
|
||||
return "_exec: Invalid parameter.\n";
|
||||
case ERROR_EXEC_EMFILE:
|
||||
return "_exec: Too many files open (the specified file must be opened to determine whether it is executable).\n";
|
||||
case ERROR_EXEC_ENOENT:
|
||||
return "_exec: The file or path not found.\n";
|
||||
case ERROR_EXEC_ENOEXEC:
|
||||
return "_exec: The specified file is not executable or has an invalid executable-file format.\n";
|
||||
case ERROR_EXEC_ENOMEM:
|
||||
return "_exec: Not enough memory is available to execute the new process; the available memory has been corrupted; or an invalid block exists, indicating that the calling process was not allocated properly.\n";
|
||||
case ERROR_EXEC_UNKNOWN:
|
||||
return "Unknown _exec error.\n";
|
||||
default:
|
||||
return "Unknown error.\n";
|
||||
}
|
||||
}
|
||||
|
||||
int main( int cArg, char* rgArg[] )
|
||||
{
|
||||
int cArgCommand = cArg; // Take one off for the name of this exe, then add
|
||||
// one for the null at the end of the arg list.
|
||||
int i; // Looping variable
|
||||
int rc = ERROR_NO_ERROR; // Return code
|
||||
char **rgArgCommand; // An array for the command args
|
||||
|
||||
// Make sure we got enough parameters to execute.
|
||||
if( cArg < 4)
|
||||
{
|
||||
fprintf(stderr, errorMessage(ERROR_MEMORY_ALLOCATION_FAILED));
|
||||
fprintf( stderr, "Usage: %s <full path path to java.exe> <-cp classpath> <class> [arg1 [arg2 [...]]]\n", rgArg[0] );
|
||||
return ERROR_INVALID_NUMBER_OF_PARAMETERS;
|
||||
}
|
||||
|
||||
// Allocate room to the arglist for the cal to exec
|
||||
rgArgCommand = (char **)malloc(sizeof(char *)*cArgCommand);
|
||||
|
||||
// Did the memory allocation succeed?
|
||||
if (NULL == rgArgCommand)
|
||||
{
|
||||
fprintf(stderr, errorMessage(ERROR_MEMORY_ALLOCATION_FAILED));
|
||||
return ERROR_MEMORY_ALLOCATION_FAILED;
|
||||
}
|
||||
|
||||
fprintf( stderr, "Arg count = %d\n", cArg);
|
||||
fprintf( stderr, "Command arg count = %d\n", cArgCommand);
|
||||
|
||||
// copy over the arguments for the command
|
||||
for (i = 1; i < cArg; i++)
|
||||
{
|
||||
fprintf(stderr, "rgArgCommand[%d] = rgArg[%d] (%s)\n", (i - 1), i, rgArg[i]);
|
||||
rgArgCommand[i - 1] = rgArg[i];
|
||||
}
|
||||
|
||||
// null out the command arg array
|
||||
fprintf( stderr, "null out rgArgCommand[%d]\n",i);
|
||||
rgArgCommand[cArgCommand - 1] = (char *)0;
|
||||
|
||||
// exec the command
|
||||
if (-1 == _execv( rgArg[1], rgArgCommand))
|
||||
{
|
||||
switch (errno)
|
||||
{
|
||||
case E2BIG: // The space required for the arguments and environment settings exceeds 32 KB.
|
||||
rc = ERROR_EXEC_E2BIG;
|
||||
break;
|
||||
|
||||
case EACCES: // The specified file has a locking or sharing violation.
|
||||
rc = ERROR_EXEC_EACCES;
|
||||
break;
|
||||
|
||||
case EINVAL: // Invalid parameter.
|
||||
rc = ERROR_EXEC_EINVAL;
|
||||
break;
|
||||
|
||||
case EMFILE: // Too many files open (the specified file must be opened to determine whether it is executable).
|
||||
rc = ERROR_EXEC_EMFILE;
|
||||
break;
|
||||
|
||||
case ENOENT: // The file or path not found.
|
||||
rc = ERROR_EXEC_ENOENT;
|
||||
break;
|
||||
|
||||
case ENOEXEC: // The specified file is not executable or has an invalid executable-file format.
|
||||
rc = ERROR_EXEC_ENOEXEC;
|
||||
break;
|
||||
|
||||
case ENOMEM: // Not enough memory is available to execute the new process; the available memory has been
|
||||
// corrupted; or an invalid block exists, indicating that the calling process was not allocated
|
||||
// properly.
|
||||
rc = ERROR_EXEC_ENOMEM;
|
||||
break;
|
||||
|
||||
default:
|
||||
rc = ERROR_EXEC_UNKNOWN;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
free(rgArgCommand);
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,499 @@
|
||||
// CommandLauncher.cpp : Defines the entry point for the application.
|
||||
//
|
||||
|
||||
#include "stdafx.h"
|
||||
#include "CommandLauncher.h"
|
||||
#include "string.h"
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <conio.h>
|
||||
#include <process.h>
|
||||
#include <errno.h>
|
||||
|
||||
WCHAR ** G_rgArgs; // Command line arguments
|
||||
int G_cArg; // Count of command line arguments
|
||||
FILE * G_pf;
|
||||
|
||||
// Forward declarations of functions included in this code module:
|
||||
int processArguments(LPTSTR lpCmdLine);
|
||||
void freeArgs();
|
||||
int countArgs(LPTSTR lpCmdLine);
|
||||
int addArg(int iArg, LPTSTR lpString, int cChar);
|
||||
void log(LPTSTR szMessage);
|
||||
_TCHAR * errorMessage(int err);
|
||||
int executeCommand( int cArg, _TCHAR* rgArg[]);
|
||||
|
||||
|
||||
#define ERROR_NO_ERROR 0
|
||||
#define ERROR_MEMORY_ALLOCATION_FAILED -1
|
||||
#define ERROR_INVALID_NUMBER_OF_PARAMETERS -2
|
||||
#define ERROR_EXEC_E2BIG -3
|
||||
#define ERROR_EXEC_EACCES -4
|
||||
#define ERROR_EXEC_EINVAL -5
|
||||
#define ERROR_EXEC_EMFILE -6
|
||||
#define ERROR_EXEC_ENOENT -7
|
||||
#define ERROR_EXEC_ENOEXEC -8
|
||||
#define ERROR_EXEC_ENOMEM -9
|
||||
#define ERROR_EXEC_UNKNOWN -10
|
||||
#define ERROR_STRCPY_FAILED -11
|
||||
#define ERROR_JAVA_EXE_ARG_MISSING -12
|
||||
#define ERROR_JAVA_CLASSPATH_OPTION_ARG_MISSING -13
|
||||
#define ERROR_JAVA_CLASSPATH_ARG_MISSING -14
|
||||
#define ERROR_BAD_COMMAND_LINE -15
|
||||
|
||||
|
||||
|
||||
int APIENTRY _tWinMain(HINSTANCE hInstance,
|
||||
HINSTANCE hPrevInstance,
|
||||
LPTSTR lpCmdLine,
|
||||
int nCmdShow)
|
||||
{
|
||||
UNREFERENCED_PARAMETER(hInstance);
|
||||
UNREFERENCED_PARAMETER(hPrevInstance);
|
||||
UNREFERENCED_PARAMETER(lpCmdLine);
|
||||
UNREFERENCED_PARAMETER(nCmdShow);
|
||||
|
||||
int rc;
|
||||
|
||||
_wfopen_s(&G_pf, L"C:\\CommandLauncher.log", L"a+");
|
||||
|
||||
// Process the command line
|
||||
if (ERROR_NO_ERROR != (rc = processArguments(lpCmdLine)))
|
||||
{
|
||||
return rc;
|
||||
}
|
||||
|
||||
rc = executeCommand(G_cArg, G_rgArgs);
|
||||
|
||||
log(errorMessage(rc));
|
||||
|
||||
fwprintf(G_pf, L"CommandLauncher: return = %d\n", rc);
|
||||
|
||||
fclose(G_pf);
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
|
||||
// <java exe path> -cp <classpath> class k1=v1 k2=k2
|
||||
int processArguments(LPTSTR lpCmdLine)
|
||||
{
|
||||
int iArg;
|
||||
int iChar;
|
||||
int iAssignment;
|
||||
int iClassStart;
|
||||
int iClassEnd;
|
||||
int iClassPathStart;
|
||||
int iClassPathEnd;
|
||||
int rc;
|
||||
bool fClasspathOptionFound = false;
|
||||
int iKeyStart;
|
||||
int iValueEnd;
|
||||
|
||||
fwprintf( G_pf, L"current command line = %s\n", lpCmdLine);
|
||||
|
||||
|
||||
// Validate the command line
|
||||
if (NULL == lpCmdLine || (WCHAR)0 == *lpCmdLine)
|
||||
{
|
||||
return ERROR_BAD_COMMAND_LINE;
|
||||
}
|
||||
|
||||
// Count the arguments on the command line. TThe name of this executable
|
||||
// is not included in the count.
|
||||
G_cArg = countArgs(lpCmdLine);
|
||||
|
||||
// Make sure we got enough to exec something. There must be at least the
|
||||
// path to jave.exe, the classpath option, the classpath and a class.
|
||||
if (G_cArg < 4)
|
||||
{
|
||||
return ERROR_INVALID_NUMBER_OF_PARAMETERS;
|
||||
}
|
||||
|
||||
// Allocate an array of wide string for the arguments, add 1 for a NULL at
|
||||
// the end of the array
|
||||
G_rgArgs = (WCHAR**)malloc((G_cArg + 1) * sizeof(WCHAR *));
|
||||
if (NULL == G_rgArgs)
|
||||
{
|
||||
return ERROR_MEMORY_ALLOCATION_FAILED;
|
||||
}
|
||||
|
||||
// Null out the array
|
||||
memset(G_rgArgs, 0, (G_cArg + 1) * sizeof(WCHAR *));
|
||||
|
||||
// Find the java.exe argument
|
||||
iChar = 0;
|
||||
for (iChar = 0; 0 != lpCmdLine[iChar + 4]; iChar++)
|
||||
{
|
||||
if (0 == _wcsnicmp(lpCmdLine + iChar, L".exe", 4))
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (0 == lpCmdLine[iChar + 4])
|
||||
{
|
||||
rc = ERROR_JAVA_EXE_ARG_MISSING;
|
||||
goto ErrorOut;
|
||||
}
|
||||
|
||||
// Add the java.exe argument
|
||||
if (ERROR_NO_ERROR != (rc = addArg(0, lpCmdLine, iChar + 4)))
|
||||
{
|
||||
goto ErrorOut;
|
||||
}
|
||||
|
||||
// Move past the java.exe argument
|
||||
iChar += 4;
|
||||
|
||||
// Move past any spaces
|
||||
for (;L' ' == lpCmdLine[iChar]; iChar++)
|
||||
{
|
||||
// Intentionally left blank
|
||||
}
|
||||
|
||||
// Find the classpath argument
|
||||
for (; 0 != lpCmdLine[iChar + 3]; iChar++)
|
||||
{
|
||||
if (0 == _wcsnicmp(lpCmdLine + iChar, L"-cp", 3))
|
||||
{
|
||||
fClasspathOptionFound = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!fClasspathOptionFound)
|
||||
{
|
||||
rc = ERROR_JAVA_CLASSPATH_OPTION_ARG_MISSING;
|
||||
goto ErrorOut;
|
||||
}
|
||||
if (0 == lpCmdLine[iChar + 3])
|
||||
{
|
||||
rc = ERROR_JAVA_CLASSPATH_ARG_MISSING;
|
||||
goto ErrorOut;
|
||||
}
|
||||
|
||||
// Add the classpath option argument
|
||||
if (ERROR_NO_ERROR != (rc = addArg(1, L"-cp", iChar + 3)))
|
||||
{
|
||||
goto ErrorOut;
|
||||
}
|
||||
|
||||
// Move past the classpath option argument
|
||||
iChar += 3;
|
||||
|
||||
// Move past any spaces
|
||||
for (;L' ' == lpCmdLine[iChar]; iChar++)
|
||||
{
|
||||
// Intentionally left blank
|
||||
}
|
||||
|
||||
// The classpath is next. It can have spaces in it so we need to work
|
||||
// backards from the first key/value pair, or the end of the line if
|
||||
// there are no key/value pairs.
|
||||
iClassPathStart = iChar;
|
||||
|
||||
// Find the location of the next '='
|
||||
for (; 0 != lpCmdLine[iChar] && L'=' != lpCmdLine[iChar]; iChar++)
|
||||
{
|
||||
// Intentially left blank
|
||||
}
|
||||
|
||||
// If there was a key/value pair - move to the start of the key
|
||||
if (L'=' == lpCmdLine[iChar])
|
||||
{
|
||||
iAssignment = iChar;
|
||||
|
||||
// Move back to the previous space. This should put us at the
|
||||
// beginning of the first key/value pair. Assume that all args
|
||||
// are property key/value pairs and property keys have no spaces.
|
||||
for (; L' ' != lpCmdLine[iChar] && iChar >= 0; iChar--)
|
||||
{
|
||||
// Intentially left blank
|
||||
}
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
iAssignment = 0;
|
||||
iChar--;
|
||||
}
|
||||
|
||||
// Move past any spaces (moving toward the start of the line)
|
||||
for (;L' ' == lpCmdLine[iChar]; iChar--)
|
||||
{
|
||||
// Intentionally left blank
|
||||
}
|
||||
|
||||
// This should put us at the end of the class to be executed
|
||||
iClassEnd = iChar;
|
||||
|
||||
// Move to the previous space (moving toward the start of the line)
|
||||
for (;L' ' != lpCmdLine[iChar]; iChar--)
|
||||
{
|
||||
// Intentionally left blank
|
||||
}
|
||||
|
||||
iClassStart = iChar + 1;
|
||||
|
||||
// Add the class argument
|
||||
if (ERROR_NO_ERROR != (rc = addArg(3, lpCmdLine + iClassStart, iClassEnd - iClassStart + 1)))
|
||||
{
|
||||
goto ErrorOut;
|
||||
}
|
||||
|
||||
// Move past any spaces (moving toward the start of the line)
|
||||
for (;L' ' == lpCmdLine[iChar]; iChar--)
|
||||
{
|
||||
// Intentionally left blank
|
||||
}
|
||||
|
||||
// This should put us at the end of the classpath
|
||||
iClassPathEnd = iChar;
|
||||
|
||||
// Add the class path argument
|
||||
if (ERROR_NO_ERROR != (rc = addArg(2, lpCmdLine + iClassPathStart, iClassPathEnd - iClassPathStart + 1)))
|
||||
{
|
||||
goto ErrorOut;
|
||||
}
|
||||
|
||||
// Are the any key/value pairs?
|
||||
if (0 != iAssignment)
|
||||
{
|
||||
iArg = 4;
|
||||
while (0 != lpCmdLine[iAssignment])
|
||||
{
|
||||
iKeyStart = iAssignment;
|
||||
|
||||
// Move back to the previous space. This should put us at the
|
||||
// beginning of the current next key/value pair. Assume that all args
|
||||
// are property key/value pairs and property keys have no spaces.
|
||||
for (; L' ' != lpCmdLine[iKeyStart] && iKeyStart > 0; iKeyStart--)
|
||||
{
|
||||
// Intentially left blank
|
||||
}
|
||||
if (L' ' == lpCmdLine[iKeyStart])
|
||||
{
|
||||
iKeyStart++;
|
||||
}
|
||||
|
||||
// Find the location of the next '='
|
||||
iValueEnd = iAssignment + 1;
|
||||
for (; 0 != lpCmdLine[iValueEnd] && L'=' != lpCmdLine[iValueEnd]; iValueEnd++)
|
||||
{
|
||||
// Intentially left blank
|
||||
}
|
||||
|
||||
// If there was a property...
|
||||
if (L'=' == lpCmdLine[iValueEnd])
|
||||
{
|
||||
iAssignment = iValueEnd;
|
||||
|
||||
// Move back to the previous space. This should put us at the
|
||||
// beginning of the next key/value pair. Assume that all args
|
||||
// are property key/value pairs and property keys have no spaces.
|
||||
for (; L' ' != lpCmdLine[iValueEnd] && iValueEnd >= 0; iValueEnd--)
|
||||
{
|
||||
// Intentially left blank
|
||||
}
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
// We have reached the end of the command line - back off from the
|
||||
// null terminator.
|
||||
iAssignment = iValueEnd;
|
||||
iValueEnd--;
|
||||
}
|
||||
|
||||
// Move thorugh any spaces
|
||||
for (; L' ' == lpCmdLine[iValueEnd] && iValueEnd >= 0; iValueEnd--)
|
||||
{
|
||||
// Intentially left blank
|
||||
}
|
||||
|
||||
// Add the key/value pair
|
||||
if (ERROR_NO_ERROR != (rc = addArg(iArg, lpCmdLine + iKeyStart, iValueEnd - iKeyStart + 1)))
|
||||
{
|
||||
goto ErrorOut;
|
||||
}
|
||||
|
||||
// Go on to the next arg
|
||||
iArg++;
|
||||
}
|
||||
}
|
||||
|
||||
return ERROR_NO_ERROR;
|
||||
|
||||
ErrorOut:
|
||||
|
||||
freeArgs();
|
||||
log(errorMessage(rc));
|
||||
return rc;
|
||||
}
|
||||
|
||||
void freeArgs()
|
||||
{
|
||||
int iArg;
|
||||
if (NULL != G_rgArgs)
|
||||
{
|
||||
for (iArg = 0; iArg < G_cArg; iArg++)
|
||||
{
|
||||
if (NULL != G_rgArgs[iArg])
|
||||
{
|
||||
free(G_rgArgs[iArg]);
|
||||
G_rgArgs[iArg] = NULL;
|
||||
}
|
||||
}
|
||||
free(G_rgArgs);
|
||||
G_rgArgs = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
int countArgs(LPTSTR lpCmdLine)
|
||||
{
|
||||
int cArgument;
|
||||
|
||||
// Check if the exe to execute is the only argument. Assume that all additional
|
||||
// arguments have an '=' in them.
|
||||
for (cArgument = 4; *lpCmdLine != (WCHAR)0; lpCmdLine++)
|
||||
{
|
||||
if (*lpCmdLine == L'=')
|
||||
{
|
||||
cArgument++;
|
||||
}
|
||||
}
|
||||
return cArgument;
|
||||
}
|
||||
|
||||
int addArg(int iArg, LPTSTR lpString, int cChar)
|
||||
{
|
||||
int cb = (cChar + 3) * sizeof(WCHAR); // count of bytes
|
||||
|
||||
// Allocate space for the new arg
|
||||
G_rgArgs[iArg] = (WCHAR *)malloc(cb);
|
||||
if (NULL == G_rgArgs[iArg])
|
||||
{
|
||||
return ERROR_MEMORY_ALLOCATION_FAILED;
|
||||
}
|
||||
|
||||
// Null out the argument
|
||||
memset(G_rgArgs[iArg], 0, cb);
|
||||
|
||||
// Add a starting quote
|
||||
// G_rgArgs[iArg][0] = L'\"';
|
||||
|
||||
// Copy the arg
|
||||
if (0 != wcsncpy_s(G_rgArgs[iArg], cChar + 1, lpString, cChar))
|
||||
{
|
||||
return ERROR_STRCPY_FAILED;
|
||||
}
|
||||
|
||||
// Add a terminating quote
|
||||
// G_rgArgs[iArg][cb-1] = L'\"';
|
||||
|
||||
return ERROR_NO_ERROR;
|
||||
}
|
||||
|
||||
|
||||
void log(LPTSTR szMessage)
|
||||
{
|
||||
LPTSTR szT = L"";
|
||||
if (NULL == szMessage)
|
||||
szMessage = szT;
|
||||
fwprintf(G_pf, L"JavaLauncher: %s\n", szMessage);
|
||||
}
|
||||
|
||||
_TCHAR * errorMessage(int err)
|
||||
{
|
||||
switch (err)
|
||||
{
|
||||
case ERROR_NO_ERROR:
|
||||
return L"No error\n";
|
||||
case ERROR_MEMORY_ALLOCATION_FAILED:
|
||||
return L"Memory allocation failed\n";
|
||||
case ERROR_INVALID_NUMBER_OF_PARAMETERS:
|
||||
return L"Invalid number of parameters\n";
|
||||
case ERROR_EXEC_E2BIG:
|
||||
return L"_exec: The space required for the arguments and environment settings exceeds 32 KB.\n";
|
||||
case ERROR_EXEC_EACCES:
|
||||
return L"_exec: The specified file has a locking or sharing violation.\n";
|
||||
case ERROR_EXEC_EINVAL:
|
||||
return L"_exec: Invalid parameter.\n";
|
||||
case ERROR_EXEC_EMFILE:
|
||||
return L"_exec: Too many files open (the specified file must be opened to determine whether it is executable).\n";
|
||||
case ERROR_EXEC_ENOENT:
|
||||
return L"_exec: The file or path not found.\n";
|
||||
case ERROR_EXEC_ENOEXEC:
|
||||
return L"_exec: The specified file is not executable or has an invalid executable-file format.\n";
|
||||
case ERROR_EXEC_ENOMEM:
|
||||
return L"_exec: Not enough memory is available to execute the new process; the available memory has been corrupted; or an invalid block exists, indicating that the calling process was not allocated properly.\n";
|
||||
case ERROR_EXEC_UNKNOWN:
|
||||
return L"Unknown _exec error.\n";
|
||||
case ERROR_STRCPY_FAILED:
|
||||
return L"String copy failed.\n";
|
||||
case ERROR_JAVA_CLASSPATH_OPTION_ARG_MISSING:
|
||||
return L"Classpath option \"-cp\" missing\n";
|
||||
case ERROR_JAVA_CLASSPATH_ARG_MISSING:
|
||||
return L"Classpath argument missing\n";
|
||||
case ERROR_BAD_COMMAND_LINE:
|
||||
return L"Bad command line\n";
|
||||
default:
|
||||
return L"Unknown error.\n";
|
||||
}
|
||||
}
|
||||
|
||||
int executeCommand( int cArg, _TCHAR* rgArg[] )
|
||||
{
|
||||
int i; // Looping variable
|
||||
int rc = ERROR_NO_ERROR; // Return code
|
||||
|
||||
fwprintf( G_pf, L"Arg count = %d\n", cArg);
|
||||
for (i = 0; i < cArg; i++)
|
||||
{
|
||||
fwprintf(G_pf, L"rgArg[%d] (%s)\n", i, rgArg[i]);
|
||||
}
|
||||
|
||||
// exec the command
|
||||
// if (-1 == _wexecv( rgArg[0], rgArg))
|
||||
if (-1 == _wspawnv(_P_WAIT, rgArg[0], rgArg))
|
||||
{
|
||||
switch (errno)
|
||||
{
|
||||
case E2BIG: // The space required for the arguments and environment settings exceeds 32 KB.
|
||||
rc = ERROR_EXEC_E2BIG;
|
||||
break;
|
||||
|
||||
case EACCES: // The specified file has a locking or sharing violation.
|
||||
rc = ERROR_EXEC_EACCES;
|
||||
break;
|
||||
|
||||
case EINVAL: // Invalid parameter.
|
||||
rc = ERROR_EXEC_EINVAL;
|
||||
break;
|
||||
|
||||
case EMFILE: // Too many files open (the specified file must be opened to determine whether it is executable).
|
||||
rc = ERROR_EXEC_EMFILE;
|
||||
break;
|
||||
|
||||
case ENOENT: // The file or path not found.
|
||||
rc = ERROR_EXEC_ENOENT;
|
||||
break;
|
||||
|
||||
case ENOEXEC: // The specified file is not executable or has an invalid executable-file format.
|
||||
rc = ERROR_EXEC_ENOEXEC;
|
||||
break;
|
||||
|
||||
case ENOMEM: // Not enough memory is available to execute the new process; the available memory has been
|
||||
// corrupted; or an invalid block exists, indicating that the calling process was not allocated
|
||||
// properly.
|
||||
rc = ERROR_EXEC_ENOMEM;
|
||||
break;
|
||||
|
||||
default:
|
||||
rc = ERROR_EXEC_UNKNOWN;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
fwprintf(G_pf, L"ExecuteCommand returning %d\n", rc);
|
||||
return rc;
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
#pragma once
|
||||
|
||||
#include "resource.h"
|
||||
@@ -4,6 +4,8 @@
|
||||
Version="8.00"
|
||||
Name="CommandLauncher"
|
||||
ProjectGUID="{B52EF84A-D745-4637-9F59-DBD6E21C179C}"
|
||||
RootNamespace="CommandLauncher"
|
||||
Keyword="Win32Proj"
|
||||
>
|
||||
<Platforms>
|
||||
<Platform
|
||||
@@ -15,9 +17,10 @@
|
||||
<Configurations>
|
||||
<Configuration
|
||||
Name="Debug|Win32"
|
||||
OutputDirectory="./bin"
|
||||
OutputDirectory="bin"
|
||||
IntermediateDirectory="$(ConfigurationName)"
|
||||
ConfigurationType="1"
|
||||
CharacterSet="1"
|
||||
>
|
||||
<Tool
|
||||
Name="VCPreBuildEventTool"
|
||||
@@ -36,6 +39,15 @@
|
||||
/>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="0"
|
||||
PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS"
|
||||
MinimalRebuild="true"
|
||||
BasicRuntimeChecks="3"
|
||||
RuntimeLibrary="3"
|
||||
UsePrecompiledHeader="2"
|
||||
WarningLevel="3"
|
||||
Detect64BitPortabilityProblems="true"
|
||||
DebugInformationFormat="4"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCManagedResourceCompilerTool"
|
||||
@@ -48,6 +60,10 @@
|
||||
/>
|
||||
<Tool
|
||||
Name="VCLinkerTool"
|
||||
LinkIncremental="2"
|
||||
GenerateDebugInformation="true"
|
||||
SubSystem="2"
|
||||
TargetMachine="1"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCALinkTool"
|
||||
@@ -76,9 +92,11 @@
|
||||
</Configuration>
|
||||
<Configuration
|
||||
Name="Release|Win32"
|
||||
OutputDirectory="./bin"
|
||||
OutputDirectory="bin"
|
||||
IntermediateDirectory="$(ConfigurationName)"
|
||||
ConfigurationType="1"
|
||||
CharacterSet="1"
|
||||
WholeProgramOptimization="1"
|
||||
>
|
||||
<Tool
|
||||
Name="VCPreBuildEventTool"
|
||||
@@ -97,6 +115,12 @@
|
||||
/>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS"
|
||||
RuntimeLibrary="2"
|
||||
UsePrecompiledHeader="2"
|
||||
WarningLevel="3"
|
||||
Detect64BitPortabilityProblems="true"
|
||||
DebugInformationFormat="3"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCManagedResourceCompilerTool"
|
||||
@@ -109,6 +133,12 @@
|
||||
/>
|
||||
<Tool
|
||||
Name="VCLinkerTool"
|
||||
LinkIncremental="1"
|
||||
GenerateDebugInformation="true"
|
||||
SubSystem="2"
|
||||
OptimizeReferences="2"
|
||||
EnableCOMDATFolding="2"
|
||||
TargetMachine="1"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCALinkTool"
|
||||
@@ -145,15 +175,47 @@
|
||||
UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}"
|
||||
>
|
||||
<File
|
||||
RelativePath=".\CommandLauncher.c"
|
||||
RelativePath=".\CommandLauncher.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\stdafx.cpp"
|
||||
>
|
||||
<FileConfiguration
|
||||
Name="Debug|Win32"
|
||||
>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
UsePrecompiledHeader="1"
|
||||
/>
|
||||
</FileConfiguration>
|
||||
<FileConfiguration
|
||||
Name="Release|Win32"
|
||||
>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
UsePrecompiledHeader="1"
|
||||
/>
|
||||
</FileConfiguration>
|
||||
</File>
|
||||
</Filter>
|
||||
<Filter
|
||||
Name="Header Files"
|
||||
Filter="h;hpp;hxx;hm;inl;inc;xsd"
|
||||
UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}"
|
||||
>
|
||||
<File
|
||||
RelativePath=".\CommandLauncher.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\Resource.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\stdafx.h"
|
||||
>
|
||||
</File>
|
||||
</Filter>
|
||||
<Filter
|
||||
Name="Resource Files"
|
||||
|
||||
@@ -57,7 +57,7 @@ package-clean clean-local:
|
||||
rm -rf Release/* Release Debug/* Debug*/Release */Debug *.log *.suo
|
||||
|
||||
clean:
|
||||
rm -rf Release/* Release Debug/* Debug */Release */Debug *.log *.suo
|
||||
rm -rf Release/* Release Debug/* Debug */Release */Debug *.log *.suo bin/* bin
|
||||
|
||||
distclean-local: package-clean
|
||||
rm -f Makefile
|
||||
|
||||
Binary file not shown.
@@ -1,3 +1,8 @@
|
||||
<?xml version='1.0' encoding='UTF-8' standalone='yes'?>
|
||||
<assembly xmlns='urn:schemas-microsoft-com:asm.v1' manifestVersion='1.0'>
|
||||
<dependency>
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity type='win32' name='Microsoft.VC80.CRT' version='8.0.50608.0' processorArchitecture='x86' publicKeyToken='1fc8b3b9a1e18e3b' />
|
||||
</dependentAssembly>
|
||||
</dependency>
|
||||
</assembly>
|
||||
|
||||
Binary file not shown.
@@ -1 +1 @@
|
||||
Manifest resource last updated at 15:03:11.42 on Wed 01/24/2007
|
||||
Manifest resource last updated at 13:12:58.17 on Wed 01/31/2007
|
||||
|
||||
Binary file not shown.
@@ -0,0 +1,31 @@
|
||||
//{{NO_DEPENDENCIES}}
|
||||
// Microsoft Visual C++ generated include file.
|
||||
// Used by CommandLauncher.rc
|
||||
//
|
||||
|
||||
#define IDS_APP_TITLE 103
|
||||
|
||||
#define IDR_MAINFRAME 128
|
||||
#define IDD_COMMANDLAUNCHER_DIALOG 102
|
||||
#define IDD_ABOUTBOX 103
|
||||
#define IDM_ABOUT 104
|
||||
#define IDM_EXIT 105
|
||||
#define IDI_COMMANDLAUNCHER 107
|
||||
#define IDI_SMALL 108
|
||||
#define IDC_COMMANDLAUNCHER 109
|
||||
#define IDC_MYICON 2
|
||||
#ifndef IDC_STATIC
|
||||
#define IDC_STATIC -1
|
||||
#endif
|
||||
// Next default values for new objects
|
||||
//
|
||||
#ifdef APSTUDIO_INVOKED
|
||||
#ifndef APSTUDIO_READONLY_SYMBOLS
|
||||
|
||||
#define _APS_NO_MFC 130
|
||||
#define _APS_NEXT_RESOURCE_VALUE 129
|
||||
#define _APS_NEXT_COMMAND_VALUE 32771
|
||||
#define _APS_NEXT_CONTROL_VALUE 1000
|
||||
#define _APS_NEXT_SYMED_VALUE 110
|
||||
#endif
|
||||
#endif
|
||||
Binary file not shown.
@@ -0,0 +1,8 @@
|
||||
// stdafx.cpp : source file that includes just the standard includes
|
||||
// CommandLauncher.pch will be the pre-compiled header
|
||||
// stdafx.obj will contain the pre-compiled type information
|
||||
|
||||
#include "stdafx.h"
|
||||
|
||||
// TODO: reference any additional headers you need in STDAFX.H
|
||||
// and not in this file
|
||||
@@ -0,0 +1,37 @@
|
||||
// stdafx.h : include file for standard system include files,
|
||||
// or project specific include files that are used frequently, but
|
||||
// are changed infrequently
|
||||
//
|
||||
|
||||
#pragma once
|
||||
|
||||
// Modify the following defines if you have to target a platform prior to the ones specified below.
|
||||
// Refer to MSDN for the latest info on corresponding values for different platforms.
|
||||
#ifndef WINVER // Allow use of features specific to Windows XP or later.
|
||||
#define WINVER 0x0501 // Change this to the appropriate value to target other versions of Windows.
|
||||
#endif
|
||||
|
||||
#ifndef _WIN32_WINNT // Allow use of features specific to Windows XP or later.
|
||||
#define _WIN32_WINNT 0x0501 // Change this to the appropriate value to target other versions of Windows.
|
||||
#endif
|
||||
|
||||
#ifndef _WIN32_WINDOWS // Allow use of features specific to Windows 98 or later.
|
||||
#define _WIN32_WINDOWS 0x0410 // Change this to the appropriate value to target Windows Me or later.
|
||||
#endif
|
||||
|
||||
#ifndef _WIN32_IE // Allow use of features specific to IE 6.0 or later.
|
||||
#define _WIN32_IE 0x0600 // Change this to the appropriate value to target other versions of IE.
|
||||
#endif
|
||||
|
||||
#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers
|
||||
// Windows Header Files:
|
||||
#include <windows.h>
|
||||
|
||||
// C RunTime Header Files
|
||||
#include <stdlib.h>
|
||||
#include <malloc.h>
|
||||
#include <memory.h>
|
||||
#include <tchar.h>
|
||||
|
||||
|
||||
// TODO: reference additional headers your program requires here
|
||||
Reference in New Issue
Block a user