Beispiel #1
0
void ShellProcess::run() {
//    QStringList sshArguments;
//    sshArguments << "-o" << "PasswordAuthentication=no" << "-o" << "ChallengeResponseAuthentication=no" << "-o" << "ConnectTimeout=2";
//    sshArguments << "-o" << "UserKnownHostsFile=/dev/null" << "-o" << "StrictHostKeyChecking=no" << "[email protected]" << "-i" << "/Users/qichunren/RubymineProjects/luna_scanner/lib/keys/yu_pri";
//    sshArguments << " touch /tmp/qichunren_qqqqqq";

//    int shellExitCode = QProcess::execute("ssh", sshArguments);
//    return;


        QString ip;
        foreach( ip, ipRange ){
            qDebug() << "ping " + ip;
            int exitCode;
       #ifdef Q_OS_WIN
            //启动一个ping进程,然后等待该进程结束。
//              exitCode = QProcess::execute("ping", QStringList() << ip << "-n 1" << "-i 2");
            QString strArg = "ping " + ip + " -n 1 -i 2";
            exitCode = QProcess::execute(strArg);
       #else
            exitCode = QProcess::execute("ping", QStringList() << "-c 1" << "-t 2" << ip);
       #endif

            if (0 == exitCode) {
                // it's alive
                qDebug() << "shell ping " + ip + " success";
                emit commandSuccess(ip);
            } else {
                qDebug() << "shell ping " + ip + " failed";
                emit commandFailed(ip);
            }
        }
Beispiel #2
0
int AsyncIOCommand::execute(AsyncIOChannel& channel)
{
	delete _pException;
	_pException = 0;

	_state = CMD_IN_PROGRESS;
	try
	{
		_result = executeImpl(channel);
		_state = CMD_COMPLETED;
		_completed.set();
		AsyncIOEvent completedEvent(this, &channel, AsyncIOEvent::EV_COMMAND_COMPLETED);
		commandCompleted(this, completedEvent);
		channel.commandCompleted(this, completedEvent);
		return _result;
	}
	catch (Exception& exc)
	{
		_pException = exc.clone();
		_state = CMD_FAILED;
		_completed.set();
		AsyncIOEvent failedEvent(this, &channel, AsyncIOEvent::EV_COMMAND_FAILED);
		commandFailed(this, failedEvent);
		channel.commandFailed(this, failedEvent);
		throw;
	}
	catch (std::exception& exc)
	{
		_pException = new Exception(exc.what());
		_state = CMD_FAILED;
		_completed.set();
		AsyncIOEvent failedEvent(this, &channel, AsyncIOEvent::EV_COMMAND_FAILED);
		commandFailed(this, failedEvent);
		channel.commandFailed(this, failedEvent);
		throw;
	}
	catch (...)
	{
		_pException = new Exception("Unknown exception");
		_state = CMD_FAILED;
		_completed.set();
		AsyncIOEvent failedEvent(this, &channel, AsyncIOEvent::EV_COMMAND_FAILED);
		commandFailed(this, failedEvent);
		channel.commandFailed(this, failedEvent);
		throw;
	}
}
Beispiel #3
0
void SessionListWidget::Update(SSHCredentials *sshCredentials, bool showFinished)
{
   QString cmd;
   SSHCommand *sshCmd = new SSHCommand(sshCredentials);
   connect(sshCmd, SIGNAL(completed(QString)), this, SLOT(queueUpdated(QString)));
   connect(sshCmd, SIGNAL(failed(QString)),    this, SLOT(commandFailed(QString)));

   if(showFinished) {
      cmd = QString("qselect -u %1 -x | xargs --no-run-if-empty qstat -fx");
   }
   else {
      cmd = QString("qselect -u %1 | xargs --no-run-if-empty qstat -f");
   }
   cmd = cmd.arg(sshCredentials->getUsername());
   sshCmd->Execute(cmd);
}
void EmacsPythonCommand::runPythonStringInsideTryExcept( const EmacsString &_command )
{
    EmacsString command( _command );

    //_dbg_msg( FormatString( "runPythonStringInsideTryExcept: Command: %s" ) << command );

    int pos=0;
    for(;;)
    {
        pos = command.index( '\n', pos );
        if( pos < 0 )
            break;
        command.insert( pos+1, '\t' );
        pos = pos + 2;
    }


    EmacsString wrapped_command( FormatString( python_try_command_except_structure ) << command );

    PyRun_SimpleString( wrapped_command.sdataHack() );

    try
    {
        Py::Module module( "__main__" );
        Py::Dict dict( module.getDict() );

        Py::Object error_reason( dict[ "__bemacs_error" ] );
        if( error_reason.isString() )
        {
            std::string reason_1 = Py::String( error_reason );
            commandFailed( EmacsString( EmacsString::copy, reason_1.c_str() ) );
        }
    }
    catch( Py::Exception &e )
    {
        //_dbg_msg( "runPythonStringInsideTryExcept: catch()" );
        e.clear();
    }
}
Beispiel #5
0
void DaewooProtocol::startSendingCommand(
  unsigned int threadableID,
  PIRKeyName command)
{
  // Exceptions here are problematic; I'll try to weed them out by putting the
  // whole thing in a try/catch block:
  try
  {
    // First, check if we are meant to be the recipient of this command:
    if (threadableID != id) return;

    clearRepeatFlag();

    KeycodeCollection::const_iterator i = keycodes.find(command);

    // Do we even have this key defined?
    if (i == keycodes.end())
    {
      QMutexLocker cifLocker(&commandIFMutex);
      commandInFlight = false;
      return;
//      std::string s = "Tried to send a non-existent command.\n";
//      throw PIRException(s);
    }

    // construct the device:
    PIRInfraredLED led(carrierFrequency, dutyCycle);

    int repeatCount = 0;
    int commandDuration = 0;
    while (repeatCount < MAX_REPEAT_COUNT)
    {
      commandDuration = generateStandardCommand((*i).second, led);

      // Now, tell the device to send the whole command:
      led.sendCommandToDevice();

      // sleep until the next repetition of command:
      sleepUntilRepeat(commandDuration);

      // Check whether we've reached the minimum required number of repetitons:
      if (repeatCount >= minimumRepetitions)
      {
        // Check whether we've been asked to stop:
        if (checkRepeatFlag())
        {
          break;
/*
          QMutexLocker cifLocker(&commandIFMutex);
          commandInFlight = false;
          return;
*/
        }
      }

      ++repeatCount;
    }

    QMutexLocker cifLocker(&commandIFMutex);
    commandInFlight = false;
  }
  catch (PIRException e)
  {
    // inform the gui:
    emit commandFailed(e.getError().c_str());
  }
}
Beispiel #6
0
void NECProtocol::startSendingCommand(
    unsigned int threadableID,
    PIRKeyName command)
{
    // Exceptions here are problematic; I'll try to weed them out by putting the
    // whole thing in a try/catch block:
    try
    {
        // First, check if we are meant to be the recipient of this command:
        if (threadableID != id) return;

        // An object that helps keep track of the number of commands:
//    PIRCommandCounter commandCounter;

        // Ok, we're going to lock down this method and make sure
        // only one guy at a time passes this point:
//    QMutexLocker commandLocker(&commandMutex);

        clearRepeatFlag();

        KeycodeCollection::const_iterator i = keycodes.find(command);

        // Do we even have this key defined?
        if (i == keycodes.end())
        {
            QMutexLocker cifLocker(&commandIFMutex);
            commandInFlight = false;
            return;
//      std::string s = "Tried to send a non-existent command.\n";
//      throw PIRException(s);
        }

        // construct the device:
        PIRInfraredLED led(carrierFrequency, dutyCycle);

        int repeatCount = 0;
        int commandDuration = 0;
        while (repeatCount < MAX_REPEAT_COUNT)
        {
            // If we are currently repeating, and have a special "repeat signal",
            // use that signal.  Otherwise, generate a normal command string.
            if (isShortRepeat && repeatCount)
            {
                commandDuration = generateRepeatCommand(led);
            }
            else
            {
                commandDuration = generateStandardCommand((*i).second, led);
            }

            // Now, tell the device to send the whole command:
            led.sendCommandToDevice();

            // sleep until the next repetition of command:
            sleepUntilRepeat(commandDuration);

            // Check whether we've reached the minimum required number of repetitons:
            if (repeatCount >= minimumRepetitions)
            {
                // Check whether we've been asked to stop:
                if (checkRepeatFlag())
                {
                    break;
                    /*
                              QMutexLocker cifLocker(&commandIFMutex);
                              commandInFlight = false;
                              return;
                    */
                }
            }

            ++repeatCount;
        }

        QMutexLocker cifLocker(&commandIFMutex);
        commandInFlight = false;
    }
    catch (PIRException e)
    {
        // inform the gui:
        emit commandFailed(e.getError().c_str());
    }
}
Beispiel #7
0
void CanalSatProtocol::startSendingCommand(
  unsigned int threadableID,
  PIRKeyName command)
{
  try
  {
    if (threadableID != id) return;

    clearRepeatFlag();

    KeycodeCollection::const_iterator i = keycodes.find(command);

    // Sanity check, make sure command exists first:
    if (i == keycodes.end())
    {
      QMutexLocker cifLocker(&commandIFMutex);
      commandInFlight = false;
      return;  // should send an error message here!!!
    }

    // Create object to communicate with device driver:
    PIRInfraredLED led(carrierFrequency, dutyCycle);

    int repeatCount = 0;
    int commandDuration = 0;
    while (repeatCount < MAX_REPEAT_COUNT)
    {
      // Construct the CanalSat command string.

      commandDuration += pushBits((*i).second, repeatCount, led);

      // Clear out the buffer, if necessary:
      if (buffer)
      {
        led.addSingle(buffer);
        commandDuration += buffer;

        buffer = 0;
        bufferContainsSpace = false;
        bufferContainsPulse = false;
      }

      // Send the command:
      led.sendCommandToDevice();

      // Sleep for the prescribed amount of time:
      sleepUntilRepeat(commandDuration);

      // Have we been told to stop?
      if (checkRepeatFlag())
      {
        break;
      }

      ++repeatCount;
    }

    QMutexLocker cifLocker(&commandIFMutex);
    commandInFlight = false;
  }
  catch (PIRException e)
  {
    emit commandFailed(e.getError().c_str());
  }
  catch (...)
  {
    emit commandFailed("Generic Error Message");
  }
}