Commit Graph

23 Commits

Author SHA1 Message Date
Brad King
e388ed687a execute_process: Improve invocation of .cmd/.bat with spaces
Extend the fix from commit 74c9d40876 (execute_process: Fix invocation
of .cmd/.bat with spaces, 2025-01-31) to work without relying on
conversion to a "short path", which may not exist.  Instead, extending
the `cmd /c` wrapper to `cmd /c call` seems to support spaces directly.

Suggested-by: Alexandru Croitor <alexandru.croitor@qt.io>
Fixes: #26655
2025-02-10 19:44:19 -05:00
Brad King
74c9d40876 execute_process: Fix invocation of .cmd/.bat with spaces
The `CreateProcessW` documentation states "to run a batch file, you must
start the command interpreter".  Use `cmd /c the.bat` to run batch files.
Also, use a "short path" to the `.bat` file if needed to avoid spaces.

Previously this worked in some cases only due to undocumented behavior
of `CreateProcessW` when given a `.bat` file.

Fixes: #26655
2025-02-03 09:13:26 -05:00
Martin Duffy
3ece058d97 execute_process: Allow setting default COMMAND_ERROR_IS_FATAL value
Issue: #26576
2025-01-15 11:12:34 -05:00
Brad King
20f059d025 execute_process: Warn on unknown ENCODING value 2024-09-17 09:20:58 -04:00
Brad King
e782811cfe execute_process: Change default ENCODING to UTF-8
Windows is heading toward making UTF-8 the preferred MBCS.  As CMake's
internal encoding, `UTF-8` is effectively equivalent to `NONE`, which
was CMake's behavior prior to 3.15's accidental change to `AUTO`.
Behavior of `ENCODING UTF-8` is independent of CMake's internal
encoding, making it in principle a better default than `NONE`.

Add policy CMP0176 for compatibility and to document the default's
history.

Fixes: #26262
2024-09-16 06:37:46 -04:00
Brad King
3898e53e82 execute_process: Document and test ENCODING default
The default was originally AUTO in commit 2ed473b3b8 (execute_process:
Add ENCODING option for Windows child process output, 2016-11-23,
v3.8.0-rc1~232^2) but was changed back to NONE by commit 07c3380a6e
(execute_process: Restore no-decoding default behavior, 2017-02-13,
v3.8.0-rc2~26^2) for CMake 3.8.  Later it was accidentally changed back
to AUTO by commit b783e62533 (cmExecuteProcessCommand: Port to
cmArgumentParser, 2019-03-25, v3.15.0-rc1~270^2) in CMake 3.15 but the
documentation was not updated.  Document the current default, AUTO, and
add a test case to verify it.

Issue: #26262
2024-09-13 08:19:57 -04:00
Brad King
e1fc4b9b17 Tests/RunCMake/execute_process: Add test for ENCODING AUTO
On Windows the AUTO encoding is based on the console code page,
so run the test in an isolated console window.
2024-09-13 08:19:32 -04:00
Brad King
56ae758bc5 Tests/RunCMake/execute_process: Improve test for ENCODING UTF-8
Generalize the test infrastructure.  Add Chinese text to the sample.
2024-09-12 14:34:04 -04:00
Brad King
374716a47a Merge topic 'execute_process-child-startup-info'
fa8c04b421 Tests/RunCMake/execute_process: Check STARTUPINFOW reserved members
d98df689ab Merge branch 'libuv-win-process-no-extra-stdio'
a590382850 libuv: win/spawn: disable extra-file-descriptor support not needed by CMake

Acked-by: Kitware Robot <kwrobot@kitware.com>
Merge-request: !9541
2024-05-28 08:56:42 -04:00
Brad King
fa8c04b421 Tests/RunCMake/execute_process: Check STARTUPINFOW reserved members
Verify that `execute_process` launches processes on Windows such that
`GetStartupInfoW` in the child does not populate `STARTUPINFOW` members
reserved for the MSVC C run-time.

Issue: #25996
2024-05-24 10:12:27 -04:00
Brad King
151a7d63dd Tests: Cover execute_process with abnormal exit on all platforms
Use a dedicated helper program instead of a Python script.
This also avoids an interactive popup on macOS.

Fixes: #25973
2024-05-14 09:32:53 -04:00
Kyle Edwards
f6d2efa752 Tests: Add case to cover execute_process support for no extension on Windows
Issue: #25450
2023-11-30 09:59:36 -05:00
Kyle Edwards
35f031e3b2 execute_process(): Restore opening files relative to WORKING_DIRECTORY
Prior to 5420639a, execute_process() would open INPUT_FILE, OUTPUT_FILE,
and ERROR_FILE relative to the WORKING_DIRECTORY argument if it was
provided. Restore this behavior for backwards compatibility.

Fixes: #25338
2023-10-16 12:23:41 -04:00
Kyle Edwards
5420639a8d cmExecuteProcessCommand: Replace cmsysProcess with cmUVProcessChain 2023-08-29 10:51:30 -04:00
Kyle Edwards
313ea361b0 CMake: Use FindPython instead of FindPythonInterp to build CMake itself
Fixes: #23444
2022-04-21 14:23:36 -04:00
Asit Dhal
e5a4ffaad1 execute_process: Improve COMMAND_ERROR_IS_FATAL error capture scenarios
1.  COMMAND_ERROR_IS_FATAL ANY will capture errors if the exit code is
    non zero, there is a timeout or an abnormal exit.

2.  COMMAND_ERROR_IS_FATAL LAST
    will capture if only the last process has an exit code non zero, there
    is a timeout or an abnormal exit.

Fixes: #21562
2020-12-10 06:09:59 -05:00
Asit Dhal
116a427eb1 execute_process: add options for fatal errors on subprocess failure
Fixes: #19930
2020-10-01 17:07:44 +02:00
Cristian Adam
6ec274b002 execute_process: Add ECHO_(OUTPUT|ERROR)_VARIABLE options
Fixes: #20378
2020-02-24 14:44:14 +01:00
Bill Hoffman
044dcf9f8d execute_process: Add option to echo command lines
Add COMMAND_ECHO option to the execute_process command. This will allow
execute_process to show the command it will run. Also add a cmake variable
CMAKE_EXECUTE_PROCESS_COMMAND_ECHO. Both the option and the variable can
be set to one of the following: STDERR|STDOUT|NONE. The command will be
printed to stderr or stdout or not at all.

Fixes: #18933
2019-04-19 13:32:08 -04:00
Craig Scott
8caec41e6e execute_process: Allow UTF-8 as a synonym for the UTF8 keyword
UTF-8 is the proper naming according to the UTF-8 RFC and is also the
name used for a similar keyword in the file() command. This commit
brings (backward compatible) consistency to the keyword names and allows
the standard UTF-8 name to be used with execute_process(). The old UTF8
keyword is still supported.
2017-12-27 21:56:00 +11:00
Adam Weisi
d6051ca39e execute_process: Add option to get results of every child
Add a `RESULTS_VARIABLE` option to get the results of all children
in a pipeline of one or more `COMMAND`s.
2017-06-10 08:03:06 -04:00
Dāvis Mosāns
2ed473b3b8 execute_process: Add ENCODING option for Windows child process output
Different applications can use different output encodings.
2016-11-30 09:06:51 -05:00
Brad King
f65bb82f36 execute_process: Improve stdout/stderr merging
Use the KWSys Process "MergeOutput" option to give the child process
the same pipe (or file) for both stdout and stderr.  This allows
natural merging of stdout and stderr together instead of merging
on arbitrary buffered read boundaries as before.
2015-05-07 14:40:38 -04:00