Last active
March 10, 2019 12:23
-
-
Save ezhov-da/3e71489a17c0a52e132791efb4b75e1d to your computer and use it in GitHub Desktop.
groovy script execute cmd command
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
[code:]groovy[:code]package ru.ezhov.groovy | |
def fileCreate = File.createTempFile("test", ".tmp") | |
def fileWriter = new FileWriter(fileCreate) | |
fileWriter.write("test all good") | |
fileWriter.flush() | |
fileWriter.close() | |
println("""file create: ${fileCreate.getAbsolutePath()}""") | |
println("file exist: ${fileCreate.exists()}") | |
def runtime = Runtime.getRuntime(); | |
def process = runtime.exec("""cmd /c del /P ${fileCreate.getAbsolutePath()}""") | |
//def process = runtime.exec("cmd /c tasklist") | |
def outputStreamWriter = new OutputStreamWriter(process.getOutputStream()) | |
outputStreamWriter.write("Y") | |
outputStreamWriter.flush() | |
outputStreamWriter.write("\r\n") | |
outputStreamWriter.close() | |
def inputStreamReader = new InputStreamReader(process.getInputStream(), "cp866") | |
inputStreamReader.each { | |
println(it) | |
} | |
inputStreamReader.close() | |
process.destroy() | |
println("file exist: ${fileCreate.exists()}") | |
[/code] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment