如何使用 ps1 脚本打开 image.png? [英] How to open image.png using ps1 script?

查看:66
本文介绍了如何使用 ps1 脚本打开 image.png?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

设置以下 $usbDriveLetter 变量以自动查找 USB 驱动器盘符,并使用该变量打开 USB 上的图像不起作用.它在 cmd 中直接打印G:\image.png".

Setting the below $usbDriveLetter variable to automatically find the USB drive letter, and using that variable to open an image on the USB doesn't work. It literally prints "G:\image.png" in the cmd.

$usbDriveLetter = (gwmi win32_volume -f 'label=''USB_NAME_HERE''').Name;
"$usbDriveLetter" + "image.png"

但如果我不使用 var 并在 PowerShell 脚本中将 "G:\" 设为静态,则图像打开就好了.

But if I don't use a var and make "G:\" static in the PowerShell script, the image opens just fine.

G:\image.png

那么我在这里做错了什么?我们如何使用ps1脚本动态打开图片?

So what am I doing wrong here? How do we dynamically open images using ps1 scripts?

推荐答案

当组合两个字符串时,您会得到一个字符串.如果引用路径 ("G:\image.png"),它的行为将相同.

When combining two strings, you get a string. If you quote the path ("G:\image.png") it will behave the same.

使用Invoke-Item执行路径:

$usbDriveLetter = (gwmi win32_volume -f 'label=''USB_NAME_HERE''').Name
Invoke-Item -Path ("$usbDriveLetter" + "image.png")

您也可以使用调用运算符 &:

You may also use the call-operator &:

$usbDriveLetter = (gwmi win32_volume -f 'label=''USB_NAME_HERE''').Name
& ("$usbDriveLetter" + "image.png")

这篇关于如何使用 ps1 脚本打开 image.png?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆