Why is execution of batch files different between drag & drop and from command line?
        Posted  
        
            by 
                Dharma Leonardi
            
        on Server Fault
        
        See other posts from Server Fault
        
            or by Dharma Leonardi
        
        
        
        Published on 2014-05-28T12:11:19Z
        Indexed on 
            2014/05/28
            15:32 UTC
        
        
        Read the original article
        Hit count: 232
        
Windows
|batch-file
Ok, so I've been trying to figure this out for hours with no progress. I have created a batch file to get details of a VHD.
Everything runs fine and produces the expected results when run from the command line in a command prompt. However, when I use drag and drop from file explorer (dragging a vhd file and dropping onto the batch file) the batch file runs without errors but the output (VHD.INFO) is empty.
I'm stumped.
Edited to only include the behaviour:
@echo off
cls
setlocal enabledelayedexpansion
set "_PATH.THIS=%~dp0"
echo HELP | diskpart > %_PATH.THIS%OUTPUT.TMP
TYPE %_PATH.THIS%OUTPUT.TMP
PAUSE
To demonstrate the different behaviour, please run the batch file from the command line once (works) and also run the batch file by double clicking in file explorer (failure in all piping commands).
© Server Fault or respective owner