Ejemplo n.º 1
0
void Executor::execProg(CmdInfoPtr cmdInfo)
{
	int res = 0;
	pid_t processId = fork();
	procError(processId, "fork");	
	if (processId == 0) {
		redirectIO(cmdInfo);
		execute(cmdInfo);
	} else {
		int statLoc;
		res = waitpid(processId, &statLoc, __WALL);
		procError(res, "wait");
	}

}		
/*!
    Constructs an assistant client with the given \a parent.
    The \a path specifies the path to the Qt Assistant executable.
    If \a path is an empty string the system path (\c{%PATH%} or \c $PATH)
    is used.
*/
QAssistantClient::QAssistantClient( const QString &path, QObject *parent )
    : QObject( parent ), host ( QLatin1String("localhost") )
{
    if ( path.isEmpty() )
        assistantCommand = QLatin1String("assistant");
    else {
        QFileInfo fi( path );
        if ( fi.isDir() )
            assistantCommand = path + QLatin1String("/assistant");
        else
            assistantCommand = path;
    }

#if defined(Q_OS_MAC)
    assistantCommand += QLatin1String(".app/Contents/MacOS/assistant");
#endif

    socket = new QTcpSocket( this );
    connect( socket, SIGNAL(connected()),
            SLOT(socketConnected()) );
    connect( socket, SIGNAL(disconnected()),
            SLOT(socketConnectionClosed()) );
    connect( socket, SIGNAL(error(QAbstractSocket::SocketError)),
             SLOT(socketError()) );
    opened = false;
    proc = new QProcess( this );
    port = 0;
    pageBuffer = QLatin1String("");
    connect( proc, SIGNAL(readyReadStandardError()),
             this, SLOT(readStdError()) );
    connect( proc, SIGNAL(error(QProcess::ProcessError)),
        this, SLOT(procError(QProcess::ProcessError)) );
}
Ejemplo n.º 3
0
int Loader::load(QString program, QString workpath, QStringList args)
{
    this->program = program;
    this->workpath = workpath;

    stop();
    connect(process, SIGNAL(readyReadStandardOutput()),this,SLOT(procReadyRead()));
    connect(process, SIGNAL(started()),this,SLOT(procStarted()));
    connect(process, SIGNAL(finished(int,QProcess::ExitStatus)),this,SLOT(procFinished(int,QProcess::ExitStatus)));
    connect(process, SIGNAL(error(QProcess::ProcessError)), this, SLOT(procError(QProcess::ProcessError)));

    process->setProcessChannelMode(QProcess::MergedChannels);
    process->setWorkingDirectory(this->workpath);
#if 0
    this->port = "";
    for(int n = 0; n < args.length(); n++) {
        QString arg = args.at(n);
        if(arg.contains("-p", Qt::CaseInsensitive)){
            this->port = args.at(n+1);
            break;
        }
    }
#endif
    this->setPlainText("");
    setReady(false);
    setDisableIO(false);
    process->start(this->program,args);

    while(running == false)
        QApplication::processEvents();

    return process->exitCode();
}
Ejemplo n.º 4
0
void Executor::execKill(CmdInfoPtr cmdInfo)
{
	int res = 0;
	
	std::vector<char*> argv;
	cmdInfo->getArgs(argv);

	if (cmdInfo->argc < 3) {
		std::cerr << "Invalid arguments: use :> kill signal pid" << std::endl;
	} else {
		int sig;
		pid_t proc;
		if (checkIsNumber(argv[1])) {
			sig = std::stoi(argv[1]);
		} else {
			std::cerr << "Invalid arguments: use :> kill signal pid" << std::endl;
			return;
		}

		if (checkIsNumber(argv[2])) {
			proc = std::stoi(argv[2]);
		} else {
			std::cerr << "Invalid arguments: use :> kill signal pid" << std::endl;
			return;
		}
		res = kill(proc, sig);
		procError(res, "cli : kill");
	}

}
Ejemplo n.º 5
0
void Executor::redirectIO(CmdInfoPtr cmdInfo)
{
	int res = 0;	
	if (!cmdInfo->input.empty()) {
		close(0);
		res = open(cmdInfo->input.c_str(), O_RDONLY);
		procError(res, "open");
	}
	if (!cmdInfo->output.empty()) {
		close(1);
		res = open(cmdInfo->output.c_str(), O_WRONLY | O_CREAT | O_TRUNC);
		procError(res, "open");
	}



}
Ejemplo n.º 6
0
RsyncDirListerOperation::RsyncDirListerOperation(RsyncDirLister* parent)
        : QObject(parent)
{
    d = new RsyncDirListerOperationData;
    d->parent = parent;
    d->id = UniqueId();
    d->url = QUrl(d->parent->url().path());
    d->syncProcess = new QProcess(this);
    connect(d->syncProcess, SIGNAL (finished(int, QProcess::ExitStatus)), this, SLOT(procFinished()));
    connect(d->syncProcess, SIGNAL (error(QProcess::ProcessError)), this, SLOT(procError()));
}
Ejemplo n.º 7
0
void Executor::execCd(CmdInfoPtr cmdInfo)
{
	int res = 0;
	std::vector<char*> argv;
	cmdInfo->getArgs(argv);
	if (cmdInfo->argc > 1) {
		res = chdir(argv[1]);
		procError(res, "cli : cd");
	}

}
Ejemplo n.º 8
0
void CustomBuildJob::start()
{
    if( type == CustomBuildSystemTool::Undefined ) {
        setError( UndefinedBuildType );
        setErrorText( i18n( "Undefined Build type" ) );
        emitResult();
    } else if( cmd.isEmpty() ) {
        setError( NoCommand );
        setErrorText( i18n( "No command given" ) );
        emitResult();
    } else if( !enabled ) {
        setError( ToolDisabled );
        setErrorText( i18n( "This command is disabled" ) );
        emitResult();
    } else {
        KShell::Errors err;
        QStringList strargs = KShell::splitArgs( arguments, KShell::AbortOnMeta, &err );
        if( err != KShell::NoError ) {
            setError( WrongArgs );
            setErrorText( i18n( "The given arguments would need a real shell, this is not supported currently." ) );
            emitResult();
        }
        setStandardToolView( KDevelop::IOutputView::BuildView );
        setBehaviours( KDevelop::IOutputView::AllowUserClose | KDevelop::IOutputView::AutoScroll );
        KDevelop::OutputModel* model = new KDevelop::OutputModel( builddir );
        model->setFilteringStrategy( KDevelop::OutputModel::CompilerFilter );
        setModel( model );

        startOutput();

        exec = new KDevelop::CommandExecutor( cmd, this );

        exec->setArguments( strargs );
        exec->setEnvironment( KDevelop::EnvironmentGroupList( KGlobal::config() ).createEnvironment( environment, KProcess::systemEnvironment() ) );
        exec->setWorkingDirectory( builddir );

        
        connect( exec, SIGNAL(completed(int)), SLOT(procFinished(int)) );
        connect( exec, SIGNAL(failed( QProcess::ProcessError )), SLOT(procError( QProcess::ProcessError )) );

        connect( exec, SIGNAL(receivedStandardError(QStringList)), model, SLOT(appendLines(QStringList)) );
        connect( exec, SIGNAL(receivedStandardOutput(QStringList)), model, SLOT(appendLines(QStringList)) );

        model->appendLine( QString("%1>%2 %3").arg( builddir ).arg( cmd ).arg( arguments ) );
        exec->start();
    }
}
Ejemplo n.º 9
0
void Executor::execute(CmdInfoPtr cmdInfo)
{
	int res = 0;
	int pipefd[2];
	if (cmdInfo->isPipe) {
        	res = pipe(pipefd);
		procError(res, "pipe", true);	
		pid_t pipedProc = fork();
		procError(pipedProc, "fork", true);
		if(pipedProc == 0) {
			res = close(pipefd[0]);
			procError(res, "close", true);
			res = dup2(pipefd[1], 1);
			res = close(pipefd[1]);
			procError(res, "dup", true);
		        execute(cmdInfo->pipeCmd);
			exit(EXIT_SUCCESS);
		} else {
			res = close(pipefd[1]);
			procError(res, "close", true);
			res = dup2(pipefd[0], 0);
			res = close(pipefd[0]);
			procError(res, "dup", true);
		}
		
	}
	switch(cmdInfo->cmdType) {
	case CmdInfo::C_LS : 	execLs(cmdInfo);
				break;
	case CmdInfo::C_PWD : 	execPwd(cmdInfo);
				break;
	case CmdInfo::C_PS :	execPs();
				break;
	case CmdInfo::C_PROG :	{
					std::vector<char*> argv;
					cmdInfo->getArgs(argv);
					res = execv(cmdInfo->command.c_str(), &argv[0]);	
					if (res == -1) {
						std::string path = "/bin/";
						path += cmdInfo->command;
						res = execv(path.c_str(), &argv[0]);	
					}	
					procError(res, "cli", true);	
					break; 
				}
	default : return;
	}
}
Ejemplo n.º 10
0
int Loader::reload(QString port)
{
    QStringList args;

    if(this->program.length() == 0) {
        QSettings settings(publisherKey, ASideGuiKey,this);
        QVariant incv = settings.value(includesKey);
        if(incv.canConvert(QVariant::String)) {
            QString s = incv.toString();
            s = QDir::fromNativeSeparators(s);
            this->program = s + "propeller-load";
#if defined(Q_WS_WIN32)
            this->program+=".exe";
#endif
        }
    }

    stop();
    connect(process, SIGNAL(readyReadStandardOutput()),this,SLOT(procReadyRead()));
    connect(process, SIGNAL(started()),this,SLOT(procStarted()));
    connect(process, SIGNAL(finished(int,QProcess::ExitStatus)),this,SLOT(procFinished(int,QProcess::ExitStatus)));
    connect(process, SIGNAL(error(QProcess::ProcessError)), this, SLOT(procError(QProcess::ProcessError)));

    process->setProcessChannelMode(QProcess::MergedChannels);
    process->setWorkingDirectory(this->workpath);

    if(port.length() > 0) {
        args.append("-p");
        args.append(port);
        args.append("-t");
    }

    setReady(false);
    setDisableIO(false);
    process->start(this->program,args);

    while(running == false)
        QApplication::processEvents();

    return process->exitCode();
}
Ejemplo n.º 11
0
void Executor::execLs(CmdInfoPtr cmdInfo)
{
		int res = 0;
		std::vector<char*> argv;
		cmdInfo->getArgs(argv);
		char* dir;
		if (cmdInfo->argc == 1) {
			dir = get_current_dir_name();	
		} else {
			dir = argv[1];
		}
		struct dirent ** entry;
		res = scandir(dir, &entry, select, alphasort);
		if (res != -1) {
		for(int i = 2; i < res; i++) {
			std::cout << entry[i]->d_name << "   ";
		}
		std::cout << std::endl;
		} else {
			procError(res, "cli : ls");
		}
		exit(EXIT_SUCCESS);
}