@@ -58,23 +58,35 @@ private suspend fun readPowerShellVersion(exePath: String): PSVersionInfo {
58
58
var process: Process ? = null
59
59
val qInner = if (SystemInfo .isWindows) ' \' ' else ' "'
60
60
val commandString = " (\$ PSVersionTable.PSVersion, \$ PSVersionTable.PSEdition) -join $qInner $qInner "
61
+ val commandLine = GeneralCommandLine (exePath, " -command" , commandString)
61
62
return coroutineScope {
62
63
try {
63
- process = GeneralCommandLine ( arrayListOf (exePath, " -command " , commandString)) .createProcess()
64
+ process = commandLine .createProcess()
64
65
fun readStream (stream : InputStream ) = async {
65
66
runInterruptible { stream.reader().use { it.readText() } }
66
67
}
67
68
68
69
val stdOutReader = readStream(process!! .inputStream)
69
- readStream(process!! .errorStream)
70
+ val stdErrReader = readStream(process!! .errorStream)
70
71
val exitCode = process!! .awaitExit()
71
72
if (exitCode != 0 ) {
72
- error(" Process exit code $exitCode ." )
73
+ val stdOut = stdOutReader.await()
74
+ val stdErr = stdErrReader.await()
75
+ val message = buildString {
76
+ append(" Process exit code $exitCode ." )
77
+ if (stdOut.isNotBlank()) {
78
+ append(" \n Standard output:\n $stdOut " )
79
+ }
80
+ if (stdErr.isNotBlank()) {
81
+ append(" \n Standard error:\n $stdErr " )
82
+ }
83
+ }
84
+ error(message)
73
85
}
74
86
75
87
PSVersionInfo .parse(stdOutReader.await().trim())
76
88
} catch (e: Exception ) {
77
- PSLanguageHostUtils .LOG .warn(" Command execution failed: ${ arrayListOf (exePath, " --version " )} ${e.message }" , e)
89
+ PSLanguageHostUtils .LOG .warn(" Command execution failed for ${commandLine.preparedCommandLine }" , e)
78
90
throw PowerShellControlFlowException (e.message, e.cause)
79
91
} finally {
80
92
process?.destroy()
0 commit comments