powershell - 通过批处理脚本调用时,Powershell 脚本中的 Out-File 无法更新或创建?
问题描述
我有一个 PowerShell 脚本,它通过 Out-File 命令将某些信息记录到文件中:
"text to be logged" | Out-File $logFile -Append
当 PowerShell 脚本直接运行时,日志文件的创建/更新没有任何问题。通过以下命令通过批处理脚本调用此 PowerShell 脚本(由于我使用的工具仅接受批处理脚本作为输入):
PowerShell -NoProfile -ExecutionPolicy Bypass -Command "& {Start-Process PowerShell -ArgumentList '-NoProfile -ExecutionPolicy Bypass -File """"%powerShellScriptPath%"""" """"%argOne%"""" """"%argTwo%""""' -Verb RunAs}";
我在上面实施的命令是基于在这个答案中找到的实现。
通过批处理脚本调用时,永远不会创建/更新日志文件。PowerShell 脚本在幕后毫无问题地执行其所有职责,它根本无法创建日志文件或用数据填充它......
解决方案
推荐阅读
- c++ - void* 地址的 int* 值
- r - 输出不包括原始变量名
- javascript - ASP.NET 从 MVC 模型数据渲染 HTML5 画布
- javascript - 在 VueJS data() 和 v-bind: 同步表单中动态设置对象值
- mysql - (MySQLdb._exceptions.OperationalError) (1045, "Access denied for user 'DELL'@'localhost' (using password: NO)")
- java - 在转换方法 WebFlux 中从 lambda 返回 null 或可为 null 的东西
- angularjs - 使用 Python 请求模块时解析 Angular.JS
- flutter - 未处理的异常:FileSystemException:无法打开文件,路径 = 'assets/xml/strings.xml'(操作系统错误:没有这样的文件或目录,errno = 2)
- css - 如何创建一个使用带有 tailwindcss 的奇子伪选择器的类
- css - 如何在 angular primeng 中设置 p-listbox 的宽度?