gpt4 book ai didi

groovy - 如何通过groovy从cmd写入日志文件? (等级)

转载 作者:行者123 更新时间:2023-12-03 06:22:28 28 4
gpt4 key购买 nike

我有一个应用程序,并且在主gradle文件中编写:

task myTask {
def command = "wsimport -s src" + File.separator + "main" + File.separator + "java -d " + classesDir + " path to my WSDL-file -b bindings/bindingFirst.xml -b bindings/bindingSecond.xml>>bindings/OutInfo.log" // Create the String
def proc = command.execute() // Call *execute* on the string
proc.waitFor() // Wait for the command to finish

// Obtain status and output
println "return code: ${ proc.exitValue()}"
println "stderr: ${proc.err.text}"
println "stdout: ${proc.in.text}" // *out* from the external program is *in* for groovy
}

遇到问题:“>> bindings / OutInfo.log”,为什么?
return code: 1
stderr: Exception in thread "main" com.sun.xml.internal.ws.streaming.XMLReaderException: Unable to create StAX reader or writer
at com.sun.xml.internal.ws.api.streaming.XMLStreamReaderFactory.create(XMLStreamReaderFactory.java:134)
at com.sun.tools.internal.ws.wscompile.WsimportOptions.parseBindings(WsimportOptions.java:430)
at com.sun.tools.internal.ws.wscompile.WsimportTool.run(WsimportTool.java:162)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at com.sun.tools.internal.ws.Invoker.invoke(Invoker.java:120)
at com.sun.tools.internal.ws.WsImport.main(WsImport.java:42)
Caused by: java.io.FileNotFoundException: /home/.../exampleWsimport/bindings/bindingSecond.xml>>bindings/OutInfo.log (No such file or directory)
at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.<init>(FileInputStream.java:146)
at java.io.FileInputStream.<init>(FileInputStream.java:101)
at sun.net.www.protocol.file.FileURLConnection.connect(FileURLConnection.java:90)
at sun.net.www.protocol.file.FileURLConnection.getInputStream(FileURLConnection.java:188)
at java.net.URL.openStream(URL.java:1037)
at com.sun.xml.internal.ws.api.streaming.XMLStreamReaderFactory.create(XMLStreamReaderFactory.java:132)
... 8 more

如何写命令wsimpot的日志文件结果? (在gradle(groovy))

最佳答案

您不能像这样进行流重定向,可以尝试:

def fs = File.separator

def command = "wsimport -s src${fs}main${fs}java -d $classesDir path to my WSDL-file -b bindings${fs}bindingFirst.xml -b bindings${fs}bindingSecond.xml"

new File( 'bindings/OutInfo.log' ).withWriterAppend { out ->
out << command.execute().text
}

关于groovy - 如何通过groovy从cmd写入日志文件? (等级),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22476216/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com