Running applications within PowerShell window

末鹿安然 提交于 2019-12-11 05:27:49

问题


I'm trying to move away from Command Prompt, because it's a dead-end, over to PowerShell (ISE). I haven't figured out how to run command-line applications within the PowerShell (ISE) window. Everytime I use Start-Process a Command Prompt window appears (and disappears). I've seen some people suggest -Wait and -NoNewWindow but those haven't worked for me so far.

Start-Process MyApplication.exe

This starts Command Prompt, runs the application and disappears. PowerShell remains responsive.

Start-Process MyApplication.exe -Wait

This starts Command Prompt, runs the application and disappears. PowerShell doesn't get responsive until Command Prompt has exited.

Start-Process MyApplication.exe -Wait -NoNewWindow

This results in the following:

Start-Process : This command cannot be run due to the error: The system can not find the file specified.


回答1:


. in PowerShell represents the current directory. This is to ensure that a user is not fooled into running a malicious executable at a folder specified by the $env:Path environment variable.

From the about_Command_Precedence help content:

As a security feature, Windows PowerShell does not run executable (native) commands, including Windows PowerShell scripts, unless the command is located in a path that is listed in the Path environment variable ($env:path) or unless you specify the path to the script file.

To run a script that is in the current directory, specify the full path, or type a dot (.) to represent the current directory.

For example, to run the FindDocs.ps1 file in the current directory, type:

   .\FindDocs.ps1


来源:https://stackoverflow.com/questions/24502118/running-applications-within-powershell-window

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!