Björn
Björn

Reputation: 13207

How to call cmd batch from within powershell script

I have

C:\folder\tail.exe

C:\logs\logfile.log

C:\script\shellscript.ps1

How do I run the C:\folder\tail.exe from within the C:\script\shellscript.ps1

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.

Normally I do: cd C:\folder\ and then tailf.exe C:\logs\logfile.log

Inside C:\script\shellscript.ps1 I tried

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.

Upvotes: 2

Views: 4981

Answers (2)

jon Z
jon Z

Reputation: 16616

  1. To accomplish tail.exe running in a separate window and not having the window closed immediately, try:

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

  2. To start tail.exe in the powershell window, try:

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

  3. Assuming tail.exe is Tail for Win32, this is a powershell equivalent of your command:

    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.

Upvotes: 3

manojlds
manojlds

Reputation: 301037

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"

Upvotes: 7

Related Questions