简体   繁体   English

如何从powershell脚本中调用cmd批处理

[英]How to call cmd batch from within powershell script

I have 我有

C:\\folder\\tail.exe C:\\文件夹\\ tail.exe

C:\\logs\\logfile.log C:\\日志\\ LOGFILE.LOG

C:\\script\\shellscript.ps1 C:\\脚本\\ shellscript.ps1

How do I run the C:\\folder\\tail.exe from within the C:\\script\\shellscript.ps1 如何从C:\\ script \\ shellscript.ps1中运行C:\\ folder \\ tail.exe

I need to run "C:\\folder\\tailf.exe C:\\logs\\logfile.log" from within C:\\script\\shellscript.ps1 but without relying a seperate batch file, i need to call it directly. 我需要在C:\\ script \\ shellscript.ps1中运行“C:\\ folder \\ tailf.exe C:\\ logs \\ logfile.log”,但不依赖于单独的批处理文件,我需要直接调用它。

Normally I do: cd C:\\folder\\ and then tailf.exe C:\\logs\\logfile.log 通常我这样做:cd C:\\ folder \\然后是tailf.exe C:\\ logs \\ logfile.log

Inside C:\\script\\shellscript.ps1 I tried 在C:\\ script \\ shellscript.ps1里面我试过了

start-process C:\fetchmail\tail.exe -argumentlist "C:\fetchmail\logs\fetchmail.log"

i can see a window flashing but dont know if it works, the window should stay open. 我可以看到一个窗口闪烁,但不知道它是否有效,窗口应保持打开状态。

You can do what you normally do: 你可以做你通常做的事情:

C:\folder\tail.exe c:\logs\logfile.log

Note that if the paths have spaces in them you have to do: 请注意,如果路径中包含空格,则必须执行以下操作:

& "C:\fol der\tail.exe" "c:\log s\logfile.log"
  1. To accomplish tail.exe running in a separate window and not having the window closed immediately , try: 要在单独的窗口中运行tail.exe并且不立即关闭窗口 ,请尝试:

    cmd /kc:\\folder\\tail.exe c:\\logs\\test.log

  2. To start tail.exe in the powershell window, try: 要在powershell窗口中启动tail.exe,请尝试:

    C:\\folder\\tail.exe c:\\logs\\logfile.log

  3. Assuming tail.exe is Tail for Win32 , this is a powershell equivalent of your command: 假设tail.exeWin32的Tail ,这是一个与命令相当的tail.exe

    get-content c:\\logs\\logfile.log | select -last 10

  4. In the Powershell Community Extensions there is a Get-FileTail cmdlet which is a more efficient native powershell tail equivalent. Powershell社区扩展中,有一个Get-FileTail cmdlet,它是一个更有效的本机PowerShell尾部等效项。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM