11package org.utbot.instrumentation.process
22
3+ import mu.KotlinLogging
34import org.utbot.common.bracket
45import org.utbot.common.debug
56import org.utbot.common.firstOrNullResourceIS
@@ -9,11 +10,11 @@ import org.utbot.common.pid
910import org.utbot.common.scanForResourcesContaining
1011import org.utbot.common.utBotTempDirectory
1112import org.utbot.framework.JdkPathService
13+ import org.utbot.framework.UtSettings
1214import org.utbot.instrumentation.Settings
1315import org.utbot.instrumentation.agent.DynamicClassTransformer
1416import java.io.File
1517import java.nio.file.Paths
16- import mu.KotlinLogging
1718
1819private val logger = KotlinLogging .logger {}
1920private var processSeqN = 0
@@ -30,19 +31,24 @@ class ChildProcessRunner {
3031 debugCmd + listOf (" -javaagent:$jarFile " , " -ea" , " -jar" , " $jarFile " )
3132 }
3233
33- lateinit var errorLogFile: File
34+ var errorLogFile: File = NULL_FILE
3435
3536 fun start (): Process {
3637 logger.debug { " Starting child process: ${cmds.joinToString(" " )} " }
3738 processSeqN++
3839
39- val dir = File (utBotTempDirectory.toFile(), ERRORS_FILE_PREFIX )
40- dir.mkdirs()
41- errorLogFile = File (dir, " ${hashCode()} -${processSeqN} .log" )
40+ if (UtSettings .logConcreteExecutionErrors) {
41+ UT_BOT_TEMP_DIR .mkdirs()
42+ errorLogFile = File (UT_BOT_TEMP_DIR , " ${hashCode()} -${processSeqN} .log" )
43+ }
4244
4345 val processBuilder = ProcessBuilder (cmds).redirectError(errorLogFile)
4446 return processBuilder.start().also {
45- logger.debug { " Process started with PID=${it.pid} , error log: ${errorLogFile.absolutePath} " }
47+ logger.debug { " Process started with PID=${it.pid} " }
48+
49+ if (UtSettings .logConcreteExecutionErrors) {
50+ logger.debug { " Child process error log: ${errorLogFile.absolutePath} " }
51+ }
4652 }
4753 }
4854
@@ -53,6 +59,16 @@ class ChildProcessRunner {
5359
5460 private const val DEBUG_RUN_CMD = " -agentlib:jdwp=transport=dt_socket,server=y,suspend=y,quiet=y,address=5005"
5561
62+ private val UT_BOT_TEMP_DIR : File = File (utBotTempDirectory.toFile(), ERRORS_FILE_PREFIX )
63+
64+ private val NULL_FILE_PATH : String = if (System .getProperty(" os.name" ).startsWith(" Windows" )) {
65+ " NUL"
66+ } else {
67+ " /dev/null"
68+ }
69+
70+ private val NULL_FILE = File (NULL_FILE_PATH )
71+
5672 /* *
5773 * * Firstly, searches for utbot-instrumentation jar in the classpath.
5874 *
0 commit comments