我有一个 PowerShell 脚本,它将一些结果写入文件中。
Remove-Item。rm -f您可以在类 Unix 系统中满足上述所有要求。
首先我尝试过Remove-Item -Force,但它无法忽略不存在的文件(参见rm -f忽略不存在的文件)。
PS C:\tmp> Remove-Item C:\tmp\foo.txt -Force
Remove-Item : Cannot find path 'C:\tmp\foo.txt' because it does not exist.
At line:1 char:1
+ Remove-Item C:\tmp\foo.txt -Force
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (C:\tmp\foo.txt:String) [Remove-Item], ItemNotFoundException
+ FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.RemoveItemCommand
Run Code Online (Sandbox Code Playgroud)
接下来,我尝试了Remove-Item -ErrorAction Ignore和Remove-Item -ErrorAction SilentlyContinue,但是当它们无法删除文件时,它们不会显示错误消息(参见在这种情况rm -f下显示错误消息rm: cannot remove 'foo.txt': Operation not permitted)。
PS C:\tmp> …Run Code Online (Sandbox Code Playgroud) 在Logback中,可以使用setLevel()方法更改记录器的日志级别。但在 Logback 中,由于 logger 是单例的,setLevel() 方法的调用将影响使用同一 logger 的所有其他线程。
现在我在 Web 应用程序中使用了一个类,如下所示:
class FooService {
private void insertRecord(Foo foo) {
// insert one record to DB
}
public void insertOne(Foo foo) {
insertRecord(foo);
}
public void insertMany(List<Foo> foos) {
// I want to stop logging here
for (Foo foo: foos) {
insertRecord(foo);
}
// I want to resume logging here
}
}
Run Code Online (Sandbox Code Playgroud)
在 Spring ApplicationConfig.xml 中:
<bean id="traceAdvice"
class="org.springframework.aop.interceptor.CustomizableTraceInterceptor">
<property name="enterMessage"
value="Entering $[targetClassShortName].$[methodName]($[argumentTypes])[$[arguments]]" />
<property name="exitMessage"
value="Exiting $[targetClassShortName].$[methodName] with return value …Run Code Online (Sandbox Code Playgroud) trLinux中命令的Windows等价物是什么?
例如,tr可以用换行符替换所有冒号.这可以在Windows中完成吗?
$ echo $PATH | tr ':' '\n'
/usr/local/bin
/usr/bin
Run Code Online (Sandbox Code Playgroud)