0

I have a simple batch file named test.bat containing the following:

@echo off 
cd ..\..
echo %~dp0 

From the directory where the batch file is located I enter

.\test.bat

resulting in "Program 'test.bat' failed to run: The system cannot find the file specified At line:1 char:1 + DEV\vcpkg\test.bat"

This started when I tried to install vcpkg from github, which I've done on other machines without issue using the proven install files and instructions that comes with it. It seems the path elements are not working as expected.

In researching a solution I found https://stackoverflow.com/posts/27122098/ . Copying from it I've tried


.... To get clear understanding, let's create a batch file in a directory.

C:\script\test.bat

with contents:

@echo off
cd ..\..
echo %~dp0

When you run it from command prompt, you will see this result:

C:\script\


I'm getting the error, not the proper result.

I'm running as an administrator, and this is on an Azure hosted 64-bit VM running Windows Server 2012 R2. I've deliberately reduced it to as simple an executable as possible.

Ideas??

teamAR
  • 1
  • 4
  • 2
    It's unclear what you are asking. If a batch is located in c:\scripts you can't cd two levels up - there **IS** only level above. `echo %~dp0` will **always** reflect the location of the batch independent of current dir. –  Dec 20 '18 at 21:42
  • I think you have reduced it to much ;) + The link isn't working. What are you trying to accomplish and why do you need a combination of powershell and batch? The way the question is now, it's only a problem of batch. – T-Me Dec 21 '18 at 13:21
  • A post to github a couple days ago shows where this started. Check https://github.com/Microsoft/vcpkg/issues/5009 . The issue boils down to being unable to run any batch file with Powershell on this machine. My next step is to kill it and rebuild from a new start, which I'd like to avoid since there are other applications I'd need to rebuild. – teamAR Dec 21 '18 at 16:08
  • I don't suppose you get the issue if you use `start-process`. eg: `start-process -filepath "C:\Windows\System32\cmd.exe" -argumentlist "path\to\your\cmd.bat"`? – Dan Dec 21 '18 at 16:50
  • You should always use Absolute Paths when running scripts. Sometimes you can't predict where the starting directory is. i.e. typically, running scripts may start in `C:\Windows\System32\`. Can you try running with an absolute path and see if it works? – HAL9256 Dec 21 '18 at 17:10
  • Dan, great suggestion! When I run start-process -filepath "C:\Windows\System32\cmd.exe" -argumentlist "C:\DEV\vcpkg\bootstrap-vcpkg.bat" the cmd window comes up administrator, but nothing actually runs. No error message either. No changes if I delete the vcpkg directory and clone it on the root directory, or elsewhere. – teamAR Dec 21 '18 at 18:27
  • HAL9256, good point, but the problem is the initial batch file itself won't execute. I did edit the content to use absolute paths, but since Powershell won't run the batch file (e.g. can't find it) the details re: internal commands are a moot point. – teamAR Dec 21 '18 at 18:30

1 Answers1

0

The solution was to create an entirely new VM and reinstall all.

teamAR
  • 1
  • 4