[Jsmooth-cvs] jsmooth/skeletons/util-core Process.cpp, NONE, 1.1 Process.h, NONE, 1.1 Makefile.win,
Status: Beta
Brought to you by:
reyes
From: Rodrigo R. <re...@us...> - 2007-04-28 08:48:02
|
Update of /cvsroot/jsmooth/jsmooth/skeletons/util-core In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv17460 Modified Files: Makefile.win testmain.cpp Added Files: Process.cpp Process.h Log Message: added Process class --- NEW FILE: Process.h --- /* JSmooth: a VM wrapper toolkit for Windows Copyright (C) 2003-2007 Rodrigo Reyes <re...@ch...> This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ #ifndef __JSMOOTHCOREPROCESS_H_ #define __JSMOOTHCOREPROCESS_H_ #include <process.h> #include <windows.h> #include <winbase.h> #include <string> #include <stdio.h> /** * Provides basic string operations. * * @author Rodrigo Reyes <re...@ch...> */ class Process { PROCESS_INFORMATION m_procinfo; bool m_useconsole; std::string m_commandline; bool m_started; std::string m_redirection; bool m_redirectstderr; HANDLE m_redirectHandle; public: Process(const std::string& commandline, bool useconsole); void setRedirect(const std::string& filename); bool run(); void join(); }; #endif --- NEW FILE: Process.cpp --- /* JSmooth: a VM wrapper toolkit for Windows Copyright (C) 2003-2007 Rodrigo Reyes <re...@ch...> This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ #include "Process.h" #include "StringUtils.h" Process::Process(const std::string& commandline, bool useconsole) { m_commandline = commandline; m_useconsole = useconsole; m_started = false; m_redirectHandle = INVALID_HANDLE_VALUE; } void Process::setRedirect(const std::string& filename) { m_redirection = filename; m_useconsole = true; } bool Process::run() { STARTUPINFO info; GetStartupInfo(&info); int creationFlags = 0; int inheritsHandle; if (m_useconsole == true) { info.dwFlags = STARTF_USESHOWWINDOW|STARTF_USESTDHANDLES; info.hStdOutput = GetStdHandle(STD_OUTPUT_HANDLE); info.hStdError = GetStdHandle(STD_ERROR_HANDLE); info.hStdInput = GetStdHandle(STD_INPUT_HANDLE); creationFlags = NORMAL_PRIORITY_CLASS; inheritsHandle = TRUE; } else { info.dwFlags = STARTF_USESHOWWINDOW; creationFlags = NORMAL_PRIORITY_CLASS | DETACHED_PROCESS; inheritsHandle = FALSE; } if (m_redirection.size() > 0) { SECURITY_ATTRIBUTES secattrs; secattrs.nLength = sizeof(SECURITY_ATTRIBUTES); secattrs.lpSecurityDescriptor = NULL; secattrs.bInheritHandle = TRUE; m_redirectHandle = CreateFile(m_redirection.c_str(), GENERIC_WRITE, FILE_SHARE_WRITE, &secattrs, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); if (m_redirectHandle == INVALID_HANDLE_VALUE) { return false; } info.hStdOutput = m_redirectHandle; info.hStdError = m_redirectHandle; info.dwFlags = STARTF_USESTDHANDLES; } // string exeline = StringUtils::fixQuotes(exepath) + " " + arguments; int res = CreateProcess(NULL, (char*)m_commandline.c_str(), NULL, NULL, inheritsHandle, creationFlags, NULL, NULL, &info, &m_procinfo); if (res != 0) { m_started = true; return true; } return false; } void Process::join() { if (!m_started) return; WaitForSingleObject(m_procinfo.hProcess, INFINITE); if (m_redirectHandle != INVALID_HANDLE_VALUE) { CloseHandle(m_redirectHandle); } } Index: testmain.cpp =================================================================== RCS file: /cvsroot/jsmooth/jsmooth/skeletons/util-core/testmain.cpp,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** testmain.cpp 17 Mar 2007 08:50:38 -0000 1.2 --- testmain.cpp 28 Apr 2007 08:47:57 -0000 1.3 *************** *** 24,27 **** --- 24,37 ---- #include "StringUtils.h" #include <winnls.h> + #include "FileUtils.h" + + void _debugOutput(const std::string& text) + { + printf("%s\n", text.c_str()); + } + + void _debugWaitKey() + { + } int main(int argc, char *argv[]) *************** *** 34,37 **** --- 44,66 ---- if (res > 0) printf("result: %s\n", buffer); + + + std::string cmdlinetest = " \"this is my\ test\\\" \"here and then\""; + cmdlinetest = " \"this is my\ test here\\\" \"and\" \"then\""; + printf("splitting line <%s>\n", cmdlinetest.c_str()); + std::vector<std::string> args = StringUtils::split(cmdlinetest, " \t\n\r", "\"'", false, false); + for (int i=0; i<args.size(); i++) + { + printf("ARG[%d]=%s\n", i, args[i].c_str(), false, false); + } + + // std::string fqmethod = "void mytest1(java.lang.String test[ ] ) "; + // std::vector<std::string> t1 = StringUtils::split(fqmethod, " \t(,);][", "", false, true); + + // for (std::vector<std::string>::iterator i=t1.begin(); i != t1.end(); i++) + // printf("TOK: %s\n" , i->c_str()); + + // std::string readf = FileUtils::readFile("Log.h"); + // printf("READ: <<%s>>", readf.c_str()); } Index: Makefile.win =================================================================== RCS file: /cvsroot/jsmooth/jsmooth/skeletons/util-core/Makefile.win,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** Makefile.win 9 Apr 2007 17:19:14 -0000 1.2 --- Makefile.win 28 Apr 2007 08:47:57 -0000 1.3 *************** *** 8,12 **** MINGW = RES = ! OBJ = Log.o Thread.o FileUtils.o StringUtils.o DebugConsole.o $(RES) LIBS = -L"$(MINGW)/lib" -L"/lib" -lws2_32 INCS = -I"$(MINGW)/include" -I"$(JDK)/include" -I"$(JDK)/include/win32" --- 8,12 ---- MINGW = RES = ! OBJ = Process.o Log.o Thread.o FileUtils.o StringUtils.o DebugConsole.o $(RES) LIBS = -L"$(MINGW)/lib" -L"/lib" -lws2_32 INCS = -I"$(MINGW)/include" -I"$(JDK)/include" -I"$(JDK)/include/win32" |