Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Windows 如何在打包为exe的powershell脚本中运行本地exe_Windows_Powershell_Exe - Fatal编程技术网

Windows 如何在打包为exe的powershell脚本中运行本地exe

Windows 如何在打包为exe的powershell脚本中运行本地exe,windows,powershell,exe,Windows,Powershell,Exe,所以我在Powershell中创建了一个脚本,将其打包为exe,现在当我需要在Powershell中运行adb命令时,我似乎无法引用adb的完整路径。我使用下面的创建目录,但当我尝试调用adb(位于脚本旁边的platform tools文件夹中)时,它不会运行。相反,我看到一些临时目录,而不是我的实际exe和platform tools文件夹所在的位置 如何获取脚本的工作文件夹,以便相对于平台工具文件夹执行adb $scriptpath = $MyInvocation.MyCommand.Pat

所以我在Powershell中创建了一个脚本,将其打包为exe,现在当我需要在Powershell中运行adb命令时,我似乎无法引用adb的完整路径。我使用下面的创建目录,但当我尝试调用adb(位于脚本旁边的platform tools文件夹中)时,它不会运行。相反,我看到一些临时目录,而不是我的实际exe和platform tools文件夹所在的位置

如何获取脚本的工作文件夹,以便相对于平台工具文件夹执行adb

$scriptpath = $MyInvocation.MyCommand.Path
$dir = Split-Path $scriptpath
Write-host "My directory is $dir"

& $dir\platform-tools\adb connect $ipaddress
这是我最终决定与其他人一起去看的

Split-Path (Resolve-Path $myInvocation.MyCommand.Path)

这取决于您创建exe的方式您可能最好为主机系统上的路径设置一个环境变量,然后在脚本中使用该环境变量。我已经使用powershellGUI将powershell脚本打包到exe中。如何知道exe的运行路径?这样我就可以处理文件了。目前,我无法以exe的形式在powershell中执行命令,因为当我使用cwd时,它是从临时内存位置运行的。我需要能够在任何Windows PC上使用此脚本,而无需指定与脚本本身放在同一文件夹中的确切adb命令。