0

No doubt I have done something very simple wrong but I cant figure it out. I'm no expert, I'm writing my dissertation and am using .bat files with a series of PowerShell instructions to convert and move files around. An existing file that works executes a parser .exe in all subfolders:

powershell.exe -command "& {$start_path = 'C:\folder'; Get-ChildItem $start_path -Recurse -Directory | ForEach-Object {Set-Location $_.FullName | ".\OpenWeather6to6.exe"};}

c:\folder is a placeholder, OpenWeather6to6 is just the name I gave it.

Now the problem! I have another parser that generates SQL scripts that I want to run with the same PowerShell line. Both parsers work just fine if manually started either through explorer or CMD. But this second one won't run through .bat?? It's the exact identical script but with OpenWeatherSQL.exe.

.\OpenWeatherSQL.exe : The term '.\OpenWeatherSQL.exe' 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.
At line:1 char:156
+ ...  | ForEach-Object {Set-Location $_.FullName | .\OpenWeatherSQL.exe};}
+                                                   ~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (.\OpenWeatherSQL.exe:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

Could it have to do with the type of .exe? They're both from the same source file, I wrote them in CodeBlocks in C++, and they do pretty much the exact same thing. I'm baffled.

P.S. I know it's better to run them through a .ps1 script. However, in other places, I combined PS work with other functions that are easier to run through .bat and it doesn't really matter if its good code, it just has to do these few things and nobody will ever look at it or use it again; just need to get past this.

1 Answers1

0

I have no idea why but it works now. The command is the same as far as I can tell?? I added the complete path, I cant understand why that would be any better than a placeholder but whatever, and the name of the .exe that didnt work.

The only thing that changed is that I edited the code of the parser and recompiled it. It must be that PowerShell cant run an executable with specific code inside it somehow; although all I changed were a few output formatting details.

powershell.exe -command "& {$start_path = 'C:\Users\lmche\Desktop\OpenWeather\6to6data'; Get-ChildItem $start_path -Recurse -Directory | ForEach-Object {Set-Location $_.FullName | ".\OpenWeatherSQL.exe"};}