Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Safest way to run BAT file from Powershell script

I can not get a powershell script to execute a bat file directly. For example, this works on the command line:

.\\my-app\my-fle.bat 

When I add this command to a script, it outputs:

The term '.\\my-app\my-file.bat' is not recognized as the  name of a cmdlet, function, script file, or operable program.  Check the spelling of the name, or if a path was included,  verify that the path is correct and try again. 

I also tried the following, with the same result:

& .\\my-app\my-fle.bat & ".\\my-app\my-fle.bat" \my-app\my-fle.bat & \my-app\my-fle.bat & "\my-app\my-fle.bat" 

Note: It must return the lastexitcode as I need to verify success of batch.

like image 963
cmcginty Avatar asked Dec 17 '13 21:12

cmcginty


People also ask

How do I secure a .BAT file?

Unlike an executable file, a batch file can be opened in any text editor, making it easy to copy or modify. To protect the contents of your batch file, you must encrypt it using the native Windows 7 Encrypting File System.

Are BAT files safe to run?

BAT files are most commonly used to start programs and run maintenance utilities within Windows. The danger: A BAT file contains a series of line commands that will run if it is opened, which makes it a good option for malicious programmers.


1 Answers

cmd.exe /c '\my-app\my-file.bat' 
like image 166
cmcginty Avatar answered Sep 17 '22 17:09

cmcginty