使用C++调用带有库的powershell脚本
Call powershell script with libraries using C++
我有一个名为"email.ps1"的powershell脚本,代码如下:
$env:PSModulePath = $env:PSModulePath + ";C:TMPcodigospowershelllibraries"
. library.ps1
. inithialize.ps1
(...)
我试着用C++程序用系统命令调用它。不幸的是,该程序找不到库"library"answers"inithialize",但当我在没有C++程序的情况下使用powershell/cmd调用脚本时,它确实可以工作。
我已经试过这些电话,但没有成功
system("full_path_to_script/email.ps1")
system("powershell full_path_to_script/email.ps1")
system("powershell.exe full_path_to_script/email.ps1")
有什么想法吗?
您正在点源library.ps1
和inithialize.ps1
脚本,而不是使用Import-Module
将它们作为模块导入。因此,修改PSModulePath
变量将没有任何效果,因为它只由导入模块使用。
当点源时,你需要包括完整的路径,比如:
. C:TMPcodigospowershelllibrarieslibrary.ps1
. C:TMPcodigospowershelllibrariesinithialize.ps1
或者,您可以将这些库转换为真正的PowerShell模块。看看msdn上的帮助。
相关文章:
- 如何通过cpp程序运行shell脚本
- 在程序中编写脚本来编写和编译代码
- 如何在c++中使用system()来运行包含空格的python脚本
- 在cygwin中运行c++脚本时发生错误
- 如何将真正的字符串从python c-api转换为python脚本
- 用于将C++代码转换为 Web 程序集的脚本未终止
- 如何使用C++初始化向量;脚本化值不是数组、指针或矢量错误
- 在原子中使用犰狳与脚本
- 使用 Powershell 命令将 cpp 文件的文件夹编译为 GNU 的 g++
- 我适合在我的构建系统中使用 shell 脚本而不是AX_CHECK_COMPILE_FLAG吗?
- CANoe - 无法在 CAPL 脚本中打开.dll
- 在从Qt调用的Python脚本中导入OpenCV崩溃
- 将数组/向量发送到 c++ 脚本的 cython 示例
- 脚本的多重定义::LState
- 从C++应用获取PowerShell脚本输出
- 如何隐藏在c++中运行powershell脚本时按任意键继续
- 我的 PowerShell 脚本无法按预期工作(用于编译C++文件)
- 如何从C代码调用PowerShell脚本
- 使用C++调用带有库的powershell脚本
- 如何在Powershell脚本中引用C++枚举