Ejemplo n.º 1
0
void ScriptObject::execute(int i, int j)
{
  m_params.clear();
  m_params.append(QString::number(i));
  m_params.append(QString::number(j));
  executeProcess(true);
}
Ejemplo n.º 2
0
QString ScriptObject::handleDCOP(int function, const QStringList& args)
{
  switch (function) {
    case DCOP::setText:
      setAssociatedText(args[0]);
      break;
    case DCOP::clear:
      setAssociatedText(QString::null);
      break;
    case DCOP::execute:
      m_params = args;
      return executeProcess(true);
      break;
    case DCOP::item:
    {
      uint index = args[0].toInt();
      return index < m_params.count() ? m_params[index] : QString::null;
    }
    case DCOP::count:
      return QString::number(m_params.count());
    default:
      return KommanderWidget::handleDCOP(function, args);
  }
  return QString();
}
Ejemplo n.º 3
0
/*Checks what the userInput is and calls appropriate functions  */
void parseInput(char *userInput)
{
	userInput[strlen(userInput)-1] = '\0';//Remove the \n that fgets read
	while(*userInput && isblank(*userInput))//Ignore leading blanks
		userInput++;

	if(executeCommand(userInput) == 0){
		return;
	}

	/*We'll create the argv now */
	char **argv = split(userInput, " \t");
	if(argv == NULL)
	{
		fprintf(stderr, "failed to allocate memory\n");
		return;
	}
	char *path = argv[0];
	int err = executeProcess(path, argv);

	switch (err){
	case PROCESS_CREATED:
		free(argv);
		break;
	case COULDNT_CREATE_PROCESS:
		fprintf(stderr, "Failed to create new processn\n");
		free(argv);
		break;
	default:
		free(argv);
	}
}
Ejemplo n.º 4
0
bool Mysh::pipeToCommand(string s) {

    int pipefd[2];
    Pipe readPipe;
    int outOrErr;
    /* 为新的进程取得 readpipe
     * 如果没有找到count = 0 的pipi 则为标准输入
     */
    if (pipevector.getPipetoRead(readPipe)) {
        pipefd[0] = readPipe.readFD;
    }
    else pipefd[0] = 0;
    /* 根据 !|num 为新进程创建写pipe并初始化outOrErr
     * 要考虑写到文件还是写到已有的或是下一个新建的pipe中
     * 还要通过outOrErr向executeProcess 传递标准输出还是错误
     * 从而识别进程重定向输出还是错误到pipdfd[1]
     */
    size_t getPoint = 0;

    if ((getPoint = s.find_first_of('>')) != string::npos) {
        getPoint = s.find_first_not_of(' ', getPoint + 1);
        string pipeFile = s.substr(getPoint, s.find_first_of(" \n", getPoint + 1) - getPoint);
        s = s.substr(0, s.find_first_of('>'));
        pipefd[1] = open(pipeFile.c_str(), O_RDWR | O_CREAT | O_APPEND, 0666);// S_IRUSR | S_IWUSR);
        outOrErr = 1;
    }
    else if ((getPoint = s.find_first_of('|')) != string::npos) {
        string downNum = s.substr(getPoint + 1, s.find_first_of(" \n", getPoint + 1) - getPoint - 1);
        if (downNum == "") downNum = "0";
        int countDown = atoi(downNum.c_str());
        outOrErr = 1;
        Pipe writePipe = pipevector.getPipetoWrite(countDown);
        pipefd[1] = writePipe.writeFD;
    }
    else if ((getPoint = s.find_first_of('!')) != string::npos) {
        string downNum = s.substr(getPoint + 1, s.find_first_of(" \n", getPoint + 1) - getPoint - 1);
        if (downNum == "" ) downNum = "0";
        int countDown = atoi(downNum.c_str());
        outOrErr = 2;
        Pipe writePipe = pipevector.getPipetoWrite(countDown);
        pipefd[1] = writePipe.writeFD;
    }
    else {
        pipefd[1] = 1;
        outOrErr = 1;
    }

    return executeProcess(s, readPipe, pipefd, outOrErr);
}
Ejemplo n.º 5
0
void test_executes_processes_of_available_in_scheduler(){
	Process* process1 = generateProcess("Mozila", 50, 5);
	Process* expected1 = generateProcess("Mozila", 0, 5);
	Process* process2 = generateProcess("chrome", 100, 3);
	Process* expected2 = generateProcess("chrome", 0, 3);
	Queue_element* element;
	scheduler = createScheduler();
	addProcess(scheduler, process1);
	addProcess(scheduler, process2);
	executeProcess(scheduler, 10);
	element = (Queue_element*)scheduler->head->data;
	ASSERT(areProcessEqual(*expected2, *(Process*)element->data));
	element = (Queue_element*)scheduler->head->next->data;
	ASSERT(areProcessEqual(*expected1, *(Process*)element->data));
	free(expected1);
	free(expected2);
}
Ejemplo n.º 6
0
/**
 * Converts Java String[] to char** and delegates to executeProcess().
 */
static pid_t ProcessManager_exec(
        JNIEnv* env, jclass, jobjectArray javaCommands,
        jobjectArray javaEnvironment, jstring javaWorkingDirectory,
        jobject inDescriptor, jobject outDescriptor, jobject errDescriptor,
        jboolean redirectErrorStream) {

    // Copy commands into char*[].
    char** commands = convertStrings(env, javaCommands);

    // Extract working directory string.
    const char* workingDirectory = NULL;
    if (javaWorkingDirectory != NULL) {
        workingDirectory = env->GetStringUTFChars(javaWorkingDirectory, NULL);
    }

    // Convert environment array.
    char** environment = convertStrings(env, javaEnvironment);

    pid_t result = executeProcess(
            env, commands, environment, workingDirectory,
            inDescriptor, outDescriptor, errDescriptor, redirectErrorStream);

    // Temporarily clear exception so we can clean up.
    jthrowable exception = env->ExceptionOccurred();
    env->ExceptionClear();

    freeStrings(env, javaEnvironment, environment);

    // Clean up working directory string.
    if (javaWorkingDirectory != NULL) {
        env->ReleaseStringUTFChars(javaWorkingDirectory, workingDirectory);
    }

    freeStrings(env, javaCommands, commands);

    // Re-throw exception if present.
    if (exception != NULL) {
        if (env->Throw(exception) < 0) {
            LOGE("Error rethrowing exception!");
        }
    }

    return result;
}
Ejemplo n.º 7
0
CMakeBuildDirCreator::CMakeBuildDirCreator(const KUrl& srcDir, QWidget* parent, Qt::WindowFlags f)
	: QDialog(parent, f), m_srcFolder(srcDir)
{
	m_creatorUi = new Ui::CMakeBuildDirCreator;
	m_creatorUi->setupUi( this );
	m_creatorUi->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(false);
	
	QString cmakeBin=executeProcess("which", QStringList("cmake"));
	setCMakeBinary(KUrl(cmakeBin));
	
	connect(m_creatorUi->run, SIGNAL(clicked()), this, SLOT(runBegin()));
	connect(m_creatorUi->cmakeBin, SIGNAL(textChanged(const QString &)), this, SLOT(updated()));
	connect(m_creatorUi->buildFolder, SIGNAL(textChanged(const QString &)), this, SLOT(updated()));
	connect(m_creatorUi->buildType, SIGNAL(currentIndexChanged(const QString &)), this, SLOT(updated()));
	connect(&m_proc, SIGNAL(readyReadStandardError()), this, SLOT(addError()));
	connect(&m_proc, SIGNAL(readyReadStandardOutput()), this, SLOT(addOutput()));
	connect(&m_proc, SIGNAL(finished ( int , QProcess::ExitStatus )), this, SLOT(cmakeCommandDone ( int , QProcess::ExitStatus )));
	updated();
}
Ejemplo n.º 8
0
bool MSVCMemoryDump::miniDumpCallBack(const wchar_t* dump_path,
								  const wchar_t* minidump_id,
								  void* context,
								  EXCEPTION_POINTERS* exinfo,
								  MDRawAssertionInfo* assertion,
								  bool succeeded)
{
	if(succeeded) {

		//Launches crashreport.exe
		std::string commandLine = "owcrashreport";
		if (!_styleName.empty()) {
			commandLine += " -style=";
			commandLine += _styleName;
		}

		//Name of the memory dump
		//Use current path
		std::string memoryDumpName;

		if ( !_fileNamePrefix.empty() )
		{
			memoryDumpName += _fileNamePrefix;
			memoryDumpName += "-";
		}

		memoryDumpName += wstr2str(std::wstring(minidump_id));
		memoryDumpName += ".dmp";

		//GetModuleFileName retrieves the path of the executable file of the current process.
		std::string memoryDumpFile = wstr2str(std::wstring(dump_path));
		memoryDumpFile += memoryDumpName;

		commandLine += " -d ";
		commandLine += "\"";
		commandLine += memoryDumpFile;
		commandLine += "\"";

		commandLine += " -n ";
		commandLine += "\"";
		commandLine += _applicationName;
		commandLine += "\"";

		if (!_languageFilename.empty()) {
			commandLine += " -l ";
			commandLine += "\"";
			commandLine += _languageFilename;
			commandLine += "\"";
		}
		if (getAdditionalInfo) {
			commandLine += " -i ";
			commandLine += "\"";
			commandLine += getAdditionalInfo();
			commandLine += "\"";
		}
		
		//Flushes the logger file
		//Logger::logger.flush();

		executeProcess(commandLine);
	}	
	
	// force to terminate
	TerminateProcess(GetCurrentProcess(), 0);
	
	return succeeded;
}
Ejemplo n.º 9
0
//execute process and wait it end, returns process exit_code (fail : -1)
static int executeProcess(lua_State* plua_state)
{
    luaPushInteger(plua_state, executeProcess(luaToString(plua_state, 1, ""), luaToString(plua_state, 2, "")));
    return 1;
}
Ejemplo n.º 10
0
void ScriptObject::execute(const QString& s)
{
  m_params.clear();
  m_params.append(s);
  executeProcess(true);
}
Ejemplo n.º 11
0
void ScriptObject::execute()
{
  m_params.clear();
  executeProcess(true);
}