Russian Qt Forum

Qt => Общие вопросы => Тема начата: Racheengel от Декабрь 14, 2009, 17:49



Название: [Qt 4.6] QProcess не запускает системные утилиты
Отправлено: Racheengel от Декабрь 14, 2009, 17:49
Заметил такую проблему - в винде QProcess не запускает системные утилиты типа copy, del и т.д.
Вообще ничего не выводит, ни ошибок, тихо ничего не делает.
Бага?


Название: Re: [Qt 4.6] QProcess не запускает системные утилиты
Отправлено: SimpleSunny от Декабрь 14, 2009, 17:58
Насколько понимаю в винде "del, copy" не являются программами, чтобы их запускать, в отличие от *nix.
Можно извратится и написать свои *.bat (copy.bat, del.bat) и их уже запускать =)

P. S. Или я что-то путаю.


Название: Re: [Qt 4.6] QProcess не запускает системные утилиты
Отправлено: Пантер от Декабрь 14, 2009, 18:09
Под виндой запускаешь cmd.exe и команды передаешь в параметрах.


Название: Re: [Qt 4.6] QProcess не запускает системные утилиты
Отправлено: Racheengel от Декабрь 14, 2009, 18:10
через бантики работает, а вот вариант с cmd - нет. Вешает процесс.


Название: Re: [Qt 4.6] QProcess не запускает системные утилиты
Отправлено: Alex Custov от Декабрь 14, 2009, 18:20
в винде QProcess не запускает системные утилиты типа copy, del и т.д.

это не утилиты, это встроенные в cmd команды. Надо пробовать через cmd запускать. Например

Код
Bash
C:\Program Files\Far>cmd /C copy macros.txt macros.txt2
Скопировано файлов:         1.
 
C:\Program Files\Far>
 


Название: Re: [Qt 4.6] QProcess не запускает системные утилиты
Отправлено: Racheengel от Декабрь 14, 2009, 18:28
что есть странно, ибо в хелпе к QProcess написано, что можно вызывать как есть... И если я не ошибаюсь, до 4.6 это работало.


Название: Re: [Qt 4.6] QProcess не запускает системные утилиты
Отправлено: MoPDoBoPoT от Декабрь 14, 2009, 21:08
что есть странно, ибо в хелпе к QProcess написано, что можно вызывать как есть... И если я не ошибаюсь, до 4.6 это работало.
Ничего подобного
Цитата: QtAssistant
Notes for Windows Users
Some Windows commands (for example, dir) are not provided by separate applications, but by the command interpreter itself. If you attempt to use QProcess to execute these commands directly, it won't work. One possible solution is to execute the command interpreter itself (cmd.exe on some Windows systems), and ask the interpreter to execute the desired command.


Название: Re: [Qt 4.6] QProcess не запускает системные утилиты
Отправлено: virtual_root от Май 26, 2011, 19:53
Здравствуйте! Кто-нибудь может мне подсказать почему QProcess не запускает cmd.exe.
Пишу следующий код:
       QProcess *myProcess = new QProcess();
        myProcess->start("C:\\Temp\\os\\cmd.exe");
В этой папке я разместила несколько exe файлов: calc.exe,notepad.exe,mspaint и cmd.exe;
Любой другой файл запускается а cmd.exe нет. Почему? Может нужны какие-то дополнительные параметры для этого файла?



Название: Re: [Qt 4.6] QProcess не запускает системные утилиты
Отправлено: thechicho от Октябрь 26, 2011, 20:51
Код
C++ (Qt)
QString program = "cmd";
QStringList arguments;
arguments << "/C" << "help";
 
QProcess *cmd = new QProcess(this);
cmd->start(program, arguments);
cmd->waitForFinished();
qDebug() << cmd->readAll();
cmd->close();

только насчет cmd->close(); не уверен, надо ли?

Цитировать
Microsoft Windows XP [Version 5.1.2600]
(C) Copyright 1985-2001 Microsoft Corp.

C:\>cmd /?
Starts a new instance of the Windows XP command interpreter

CMD [/A | /U] [/Q] [/D] [/E:ON | /E:OFF] [/F:ON | /F:OFF] [/V:ON | /V:OFF]
    [[/S] [/C | /K] string]

/C      Carries out the command specified by string and then terminates
/K      Carries out the command specified by string but remains
/S      Modifies the treatment of string after /C or /K (see below)
/Q      Turns echo off
/D      Disable execution of AutoRun commands from registry (see below)
/A      Causes the output of internal commands to a pipe or file to be ANSI
/U      Causes the output of internal commands to a pipe or file to be
        Unicode
/T:fg   Sets the foreground/background colors (see COLOR /? for more info)
/E:ON   Enable command extensions (see below)
/E:OFF  Disable command extensions (see below)
/F:ON   Enable file and directory name completion characters (see below)
/F:OFF  Disable file and directory name completion characters (see below)
/V:ON   Enable delayed environment variable expansion using ! as the
        delimiter. For example, /V:ON would allow !var! to expand the
        variable var at execution time.  The var syntax expands variables
        at input time, which is quite a different thing when inside of a FOR
        loop.
/V:OFF  Disable delayed environment expansion.

/C      Carries out the command specified by string and then terminates