-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #63 from JetBrains-Research/create-run-command-lin…
…e-service Run command line service
- Loading branch information
Showing
4 changed files
with
41 additions
and
33 deletions.
There are no files selected for viewing
34 changes: 34 additions & 0 deletions
34
src/main/kotlin/org/jetbrains/research/testspark/services/RunCommandLineService.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package org.jetbrains.research.testspark.services | ||
|
||
import com.intellij.openapi.project.Project | ||
import java.io.BufferedReader | ||
import java.io.InputStreamReader | ||
|
||
class RunCommandLineService(private val project: Project) { | ||
|
||
/** | ||
* Executes a command line process and returns the output as a string. | ||
* | ||
* @param cmd The command line arguments as an ArrayList of strings. | ||
* @return The output of the command line process as a string. | ||
*/ | ||
fun runCommandLine(cmd: ArrayList<String>): String { | ||
var errorMessage = "" | ||
|
||
val process = ProcessBuilder() | ||
.command("bash", "-c", cmd.joinToString(" ")) | ||
.redirectErrorStream(true) | ||
.start() | ||
|
||
val reader = BufferedReader(InputStreamReader(process.inputStream)) | ||
var line: String? | ||
|
||
while (reader.readLine().also { line = it } != null) { | ||
errorMessage += line | ||
} | ||
|
||
process.waitFor() | ||
|
||
return errorMessage | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters