There are a lot of command line tools that are very useful, but have one flaw: They directly modify a file in place and do not allow you to specify an output file instead.
So, if you e.g. want to compare the modified file to the original, you have to make a copy first. Or, if you just want to view the modified file but keep the original or you cannot modify the file itself because it is immutable due to whatever reason (e.g. it resides on a read only medium like a cdrom), again you have to make a copy first.
My particular use case was the great tool DrpojNormalizer written by Uwe Raabe (and later replaced by ProjectMagician) which I wanted to use for showing changes in Delphi .dproj files in BeyondCompare. These tools are actually Delphi IDE plugins but both come with a command line program too. But unfortunately both modify the file in place so they are one example of the above mentioned category of tools.
Enter InplaceExeWrapper which called as
InplaceExeWrapper --expectfilenameonstdout c:\path\to\dprojnormalizercmd.exe input.dproj output.dproj
does the following:
- Create a temporary directory under %TEMP%
- Copy the input file input.dproj there
- Call the tool as
dprojnormalizer tempfile.dproj
- Copy the modified file to the output file output.dproj
- Delete the temporary directory
So basically it replaces the missing functionality of specifying an output file for the tool it calls.
Here is the full help on command line parameters and options:
Synopsis: InplaceExeWrapper [options] Executable InFile [OutFile] Parameters: Executable : Executable to call (if set to "copy" we only copy InFile to OutFile) InFile : input filename OutFile : output filename, defaults to infile Options: --CheckResult=value : If set, the executable must return the value given for this option (must be a number) --debug : if given, some debug output is written to error.txt in the temp directory and the temp directo ry will not be deleted. --ExpectFilenameOnStdout : if set, the output of the executable must contain the filename --help -? -h -H : display parameter help --ShowCmdLine : Show command line as passed to the program. --StartupLog=value : Write a startup log to the given file. --TempDir=value : directory to use for temporary files (must exist) --toStdOut : if set, output is written to stdout and InFile is not changed
The option –ExpectFilenameOnStdout can be used to detect if the called program actually worked. If the output does not contain the file name InplaceExeWrapper assumes that the call failed.
There is the special “executable” parameter “copy” which simply copies InFile to OutFile. I needed it to make the file editable in BeyondCompare. Here is the required configuration to be added to Tools -> File Formats:
Name: Delphi Project
Mask: *.dproj
Conversion:
Loading:
Path\to\InplaceExeWrapper.exe --expectfilenameonstdout "Path\To\dprojnormalizercmd.exe" %s %t
Saving:
Path\to\InplaceExeWrapper.exe copy %s %t
InplaceExeWrapper has a project page on SourceForge which includes a binary download as well as the source code.