【问题标题】:Pre-built SET environment variable doesn't work预建的 SET 环境变量不起作用
【发布时间】:2017-05-05 17:17:53
【问题描述】:

我目前正在尝试制作一个使用 Visual Studio 预构建的应用程序。

作为我的命令,我有很多使用相同部分的命令,比如说:

powershell.exe -ExecutionPolicy unrestricted C:folder1\bin\something.exe "variable1" "variable2"
powershell.exe -ExecutionPolicy unrestricted C:folder1\bin\something.exe "variable1" "variable2"
powershell.exe -ExecutionPolicy unrestricted C:folder1\bin\something.exe "variable1" "variable2"
powershell.exe -ExecutionPolicy unrestricted C:folder1\bin\something.exe "variable2" "variable4"
powershell.exe -ExecutionPolicy unrestricted C:folder1\bin\something.exe "variable3" "variable5"

我想在顶部设置一个变量来接受不变的内容,所以:powershell.exe -ExecutionPolicy unrestricted C:folder1\bin\something.exe

我目前正在这样做:

SET VAR = powershell.exe -ExecutionPolicy unrestricted C:folder1\bin\something.exe

and trying to call it this way : 

VAR "variable1" "variable2"

VAR "variable1" "variable2"

VAR "variable1" "variable2"

VAR "variable2" "variable4"

VAR "variable3" "variable5"

但这不起作用,请注意为什么?

【问题讨论】:

  • 这和C#有什么关系?

标签: powershell environment-variables


【解决方案1】:

我发现了问题,SET VAR="something"

“=”之间不能有空格

【讨论】:

    【解决方案2】:

    你为什么调用 powershell 只是为了调用另一个可执行文件?为什么不直接调用可执行文件并跳过 Powershell 层?

    SET VAR="C:folder1\bin\something.exe"
    
    VAR "variable1" "variable2"
    
    VAR "variable1" "variable2"
    
    VAR "variable1" "variable2"
    
    VAR "variable2" "variable4"
    
    VAR "variable3" "variable5"
    

    【讨论】:

    • 我必须验证可执行文件在我的脚本中是否是最新的,如果是就不要编译它。我认为最好的方法是制作一个 powershell 脚本。你有更好的主意吗?
    猜你喜欢
    • 1970-01-01
    • 2021-11-13
    • 2020-11-25
    • 1970-01-01
    • 1970-01-01
    • 2018-10-03
    • 1970-01-01
    • 2015-09-27
    相关资源
    最近更新 更多