I have an odd issue running a command from SHELL.
In my program, I am running many different commands via SHELL. I have no problem with any of them, except for the Microsoft OSCDIMG.EXE utility which I am using to build an ISO image.
As an example, I store the command that I am about to run in a variable called Cmd$ and then run it like this:
SHELL Cmd$
The contents of Cmd$ are:
"C:\Program Files (x86)\Windows Kits\10\Assessment and Deployment Kit\Deployment Tools\amd64\Oscdimg\oscdimg.exe" -m -o -u2 -udfver102 -l"Win10" -bootdata:2#p0,e,b"f:\boot\etfsboot.com"#pEF,e,b"f:\efi\microsoft\boot\efisys.bin" "f:" "c:\users\hanness\desktop\Win10.iso"
When run, I get the following error:
'C:\Program' is not recognized as an internal or external command,
operable program or batch file.
Some things to note here:
1) My QB64 Program is being run elevated. If I take that EXACT SAME command and run it from an elevated command prompt, it runs flawlessly.
2) This one is very interesting to me: If I output Cmd$ to a file called TEMP.BAT and then do a SHELL "TEMP.BAT" it works fine. Why???
Example:
OPEN "TEMP.BAT" FOR OUTPUT AS #1
PRINT #1, "@echo off"
PRINT #1, Cmd$ ' Note that Cmd$ holds the same command that fails when run as SHELL Cmd$
CLOSE #1
SHELL "TEMP.BAT"
64-Bit vs 32-Bit
This smells and feels like another problem I ran into. Bear with me because this can be a little confusing...
I had this exact same problem with the DISM command and it turned out that the problem was related to 32-bit code running 64-bit utilities. In that instance, I was running QB64 32-Bit and was calling %windir%\System32\DISM.EXE from a SHELL command. It turns out that when you are running a 32-bit program and you reference System32, Windows automatically redirects that to %windir%\SysWOW64. System32 holds 64-bit applications on Windows 64-bit, and SysWOW64 holds the 32-bit programs, so when you run a 32-bit app it redirects you to SysWOW64 so that the 32-bit app is called. The problem is that there is no 32-bit version of DISM.EXE and so you get an error. The workaround is to replace "System32" with "Sysnative", which is a virtual directory. This results in the 64-bit version being run from your 32-bit app. Note also that if you run QB64 64-Bit you won't encounter this issue because you now have a 64-bit program calling another 64-bit application.
Forward to today...
I am now running 64-Bit QB64 on a computer running 64-bit Windows 10. Note too that in my command the path to the OSCDIMG.EXE specifically references "\amd64\Oscdimg\oscdimg.exe", so I know I'm running the 64-bit version of OSCDIMG.EXE.
I have the workaround of outputting the command to a batch file and then running that batch file as noted above, but this is still bugging me. I would just be curious to know if anyone has any thoughts on what might be happening here.