jeb wrote: ↑25 May 2018 02:32
@JanAntonin
I'm missing the part where the arguments are transfered to a variable.
I am not sure whether I can understand the question. I cannot see any trap in doing this.
I am not able now to write a method not depending on the path and name (but I would appriciate it).
Problems are with deleted DQM (double quotation mark) after cmd command.
An universal method has to count that a name of a script or its path can contain anything allowed for NTFS. Percent signs, carrets and others.
I definitely wont code the method now.
@Ed Dyreen thanks for your effort, but it doesnt work. It is not a good example if you hard type the path. It has to be supposed that the script can be anywhere and we have information about its location inside %0 (or rather %~f0). Anything other is useless.
And I would need the method not only for a cmd command but for a start command and a left side and a right side of a pipe too.
The goal is this: we have a variable ourScript (which contains full path to the script not the script itself) and a variable ourData with data for this script (data are really inside the variable).
We would like to be able to launch the script %ourScript% for %ourData% by cmd and start with no loss or danger that something different is launched.
Something like
cmd /S /D /c""%ourScript%" "%ourData%""
start "title" "%ourScript%" "%ourData%"
%leftScript% %leftData% | %rightScript% %rightData%
- how it is for sure in many alternative universes where a density of idiots is much smaller than in our universe
and here is my really final version of the script (I dont claim that the work is done, I claim that I am done)
Code: Select all
@prompt -$G$S
@rem I just like this prompt, it plays no rule at all
@rem following is hard coded
@goto :jump
------------------------------------------------------------------------------------------
It would be prettier not using this hard coding. But I have realised that it is very very time consuming (in the meaning of my time not a performance). Because of that I will suppose this:
1) we are in a directory
c:\HH\zZ\
name.ext of this script is:
getArgumentsWithoutTemporaryFile_.cmd
measuring will be saved into a file:
params.txt
2) there is no metachars in the path - I mean percent signs, spaces and other nasty creatures
3) a command:
@(
echo "%%cmdcmdline:"=""%%"
)|find /V ""
results to:
"C:\WINDOWS\system32\cmd.exe /S /D /c"" ( echo ""%cmdcmdline:""=""""%"" )"""
what is 76 chars long - without a tail >)"""< and plus a new tail >& rem < one gets 76-4+6=78 chars
4) a string >###%LfPromptSP% prompt )"""< is 28 chars long
------------------------------------------------------------------------------------------
:jump
@rem it will be marked where "the original script" begins - I mean the script in the case of no complications of reading an input
@set /A runNumber=runNumber+0
@set /A runNumber=runNumber+1
@goto :thisIsRunNumber%runNumber%
@echo problem
@pause
exit
:thisIsRunNumber1
@setlocal ENABLEextensions
@setlocal DISABLEdelayedexpansion
@goto :JebsMethodForOriginalInput
:weAreBackFromMeasuringOriginaInput
@set LfPromptSP=^
prompt
@rem previous three lines cannot be deleted nor changed. One space character follows a word 'prompt' at the end
@(
echo "%%cmdcmdline:"=""%%"
rem %1###%%LfPromptSP%% prompt
)|cmd /S /D /c"c:\HH\zZ\getArgumentsWithoutTemporaryFile_.cmd"
@goto :EOF
:thisIsRunNumber2
@set /P inputA=
@set inputB="%inputA:~78,-28%"
@goto :JebsMethodForInputB
:weAreBackFromMeasuringInputInVariableInputB
@start "" c:\HH\zZ\getArgumentsWithoutTemporaryFile_.cmd %inputB%
@goto :EOF
:thisIsRunNumber3
rem the original script begins here
@echo "Hello World"
exit
@goto :EOF
***********************************************************************************************************
***********************************************************************************************************
:JebsMethodForOriginalInput
prompt X
(
@echo on
for %%b in (2) DO (
REM original parametres plus double quotation marks on both ends are: "%*"$
)
@echo off
)>>c:\HH\zZ\params.txt
@prompt -$G$S
@goto :weAreBackFromMeasuringOriginaInput
:JebsMethodForInputB
prompt X
(
@echo on
for %%b in (2) DO (
REM parametres in a variable are: %inputB:""="%$
)
@echo off
)>>c:\HH\zZ\params.txt
@prompt -$G$S
@goto :weAreBackFromMeasuringInputInVariableInputB