0

When running a batch as a post-build event from VS, some of my folders become invisible to the command line. The error log and output logs are nondescript.

In my subsequent batch, I cannot access SCP (System32\OpenSSH\scp.exe)

Build event:

IF NOT DEFINED PUBLISHING (
set PUBLISHING ='ON'
call "$(ProjectDir)Publish.bat"
PUBLISHING=
)

Changing call to start, a cmd window pops up and I have checked my variables and poked around in the environment.

  • Username is correct
  • The window is running as Admin (for other reasons)
  • PATH is fine (and shouldn't have anything to do with cd to begin with)

When poking around, if I try to change directories, it claims that System32\OpenSSH doesn't exist!
(Absolute path truncated)

What can System folders to not be accessible to an admin?

Mars
  • 2,505
  • 17
  • 26
  • Please read the Microsoft documentation about [WOW64 Implementation Details](https://learn.microsoft.com/en-us/windows/desktop/WinProg64/wow64-implementation-details). There are two `%SystemRoot%\System32` directories. Which one is used depends on execution environment, 32 or 64 bit environment. – Mofi Oct 02 '19 at 15:43
  • @Mofi Thank you for the tip! If you happen to know how to choose the execution environment, that would make for a great answer I think! If not, I'll figure it out and post it myself later – Mars Oct 03 '19 at 00:25

1 Answers1

1

Based on Mofi's comment,

Please read the Microsoft documentation about WOW64 Implementation Details. There are two %SystemRoot%\System32 directories. Which one is used depends on execution environment, 32 or 64 bit environment.

it was easy to determine that the cmd being used by VS was x86 and thus does not have access to the same System32 folder. In order to use OpenSSH\SCP, I needed to call the the x64 version of cmd.

For that, we can also refer to Mofi's other answer.

The result is something like this:
Note: Here we start a new cmd window because publish needs user input. A regular "call" should be fine too

IF NOT DEFINED PUBLISHING (
set PUBLISHING='ON'
:: We know we are currently running x86, so call other cmd without checking version
start %SystemRoot%\Sysnative\cmd.exe /C call "$(ProjectDir)Publish.bat" 
PUBLISHING=
::Needed to add for build to 'succeed', not in original script post
exit /b 0 
)
Mars
  • 2,505
  • 17
  • 26