相关疑难解决方法(0)

从Windows批处理文件调用powershell cmdlet

好的东西这么简单只是不适合我.我有一个接受单个参数的cmdlet.我试图在Windows批处理文件中调用cmdlet.批处理文件包含:

cd %SystemRoot%\system32\WindowsPowerShell\v1.0
powershell Set-ExecutionPolicy Unrestricted
powershell 'C:\convert-utf8-to-utf16.ps1 C:\test.txt'
powershell Set-ExecutionPolicy Restricted
pause
Run Code Online (Sandbox Code Playgroud)

我的ps1文件再没有做任何特别的事:

function convert-utf8-to-utf16 {   
  $tempfile = "C:\temp.txt"
  set-ExecutionPolicy Unrestricted
  get-content -Path $args[0] -encoding utf8 | out-file $tempfile -encoding Unicode
  set-ExecutionPolicy Restricted
}
Run Code Online (Sandbox Code Playgroud)

当我执行bat文件时,它只是运行完成(没有错误消息),它似乎没有创建temp.txt文件.

我可以在PS命令提示符下运行powershell命令文件,但不能在cmd中运行!

任何人有任何想法可能是错的?

谢谢

powershell batch-file

20
推荐指数
4
解决办法
7万
查看次数

正则表达式匹配包含空格的有效绝对Windows目录

我想要一个正则表达式来匹配一个有效的绝对Windows目录路径,其中目录名称可以包含空格.

示例匹配:

C:\pictures\holiday  (without trailing backslash)
C:\pictures\holiday\ (or with trailing backslash)
C:\ pictures\holiday
C:\ pictures\holiday\
C:\pictures \ holiday
C:\pictures \ holiday\
C:\pictures\ holiday \
Run Code Online (Sandbox Code Playgroud)

示例失败:

\pictures\holiday (no relative path allowed)
C:\pictures*\holiday (not a valid directory path)
Run Code Online (Sandbox Code Playgroud)

我试过了,^[a-zA-Z]:(\\\w+)*([\\])?$但这与空格不符.

我也试过^[a-zA-Z]:(\s)*(\\\w+)*(\s)*([\\])?$但是工作不正常.

正则表达式是我的最后手段.我还尝试使用非正则表达式解决方案来验证文本框,就像在这个答案中一样.但我还没有找到适用于空间的方法.

提前致谢!

regex

5
推荐指数
1
解决办法
1万
查看次数

标签 统计

batch-file ×1

powershell ×1

regex ×1