0

can anyone teach me the right way? here is my attempt code:

@echo off
SETLOCAL ENABLEEXTENSIONS ENABLEDELAYEDEXPANSION

"%~dp0..\x64\mediainfo.exe" --Inform=General;%%UniqueID/String%% "%~dp0..\files\SOURCE.avi" | clip 

this is what I got:

272951594390852679981592891584486079797 (0xCD58909D52AF1297B61A0656EC307D35)

this is what I need:

90852679981592891584486079797 (0xCD58909D52AF1297B61A0656EC30

basiclly to strip-off the output (by factor of 10 positions from left and 5 from right) and send it to clipboard. (hope its clear and thank you in advance)

gamer0
  • 945

3 Answers3

1

You first need to parse the output of mediainfo and store it into a variable before you can strip parts of it.

@echo off
For /f "delims=" %%A in ('
  C:\Temp\X\x64\mediainfo.exe --Inform^=General^;%%UniqueID/String%% "C:\Temp\X\files\SOURCE.avi"
') Do set "var=%%A"
Echo=%var:~10,-5%| clip

the output should be:

90852679981592891584486079797 (0xCD58909D52AF1297B61A0656EC30

EDIT to elaborate on the issue with mediainfo on the command line:

> mediainfo.exe --Inform=General drop.avi
General
Complete name                            : drop.avi
Format                                   : AVI
Format/Info                              : Audio Video Interleave
File size                                : 660 KiB
Duration                                 : 6 s 67 ms
Overall bit rate                         : 891 kb/s
IsTruncated                              : Yes
...snip...

And to capture the output of a special property:

> for /f "delims=" %A in ('mediainfo.exe --Inform^=General^;%Format/Info%  drop.avi') do @echo=%A
Audio Video Interleave

In a batch file all the percent signs have to be doubled.

LotPings
  • 7,231
  • I learned something from this, but no, I need the output as I stated (without ending ")" ) and also I apologize for not mentioning in the post that SOURCE.avi needs to be "%~dp0..\files\SOURCE.avi" so I tried to redo it but it doesnt work >> For /f "tokens=1" %%A in ('"%~dp0..\x64\mediainfo.exe" --Inform=General;%%UniqueID/String%% "%~dp0..\files\SOURCE.avi"') Do set "varA=%%A" Echo=%varA:~10,-5% | clip – gamer0 May 24 '18 at 14:02
  • Changed the batch above, the for /f needs to escape the = and/or ; in the mediainfo command with a caret ^ to not split into several arguments. That worked here with different arguments for a different .avi file. – LotPings May 24 '18 at 14:27
  • this new one causes error 'C:\Temp\X' is not recognized as internal or external command, operable command or batch file so I guess that %~dp0 part is not evaluated as it should by FOR ? – gamer0 May 24 '18 at 14:48
  • Either change my single quotes ' to backquotes \`` or remove theusebackq` – LotPings May 24 '18 at 14:51
  • It looks like you are always doing one bit different than my examples :-( Where do you save the batch file and where are mediainfo/the avi located? – LotPings May 24 '18 at 15:15
  • batch: C:\Temp\X\scripts\bat.bat

    mediainfo: C:\Temp\X\x64\mediainfo.exe

    avi: C:\Temp\X\files\source.avi

    and I need to use %~dp0 in my batch

    – gamer0 May 24 '18 at 15:21
  • I inserted the absolute path's into the batch, please try this last version. – LotPings May 24 '18 at 15:26
  • I am ashamed but this does not work. I copy/paste/saved your latest answer/code and when I run it the clipboard returns me: ~10,-5) – gamer0 May 24 '18 at 15:34
  • It seems to be a weird issue with the for /f, the moment there are two double quoted elements in the command it errors out, with only one d'quoted - either mediainfo or the avi it works here. – LotPings May 24 '18 at 16:03
  • would this somehow resolve it if I would use alias before FOR? something like: set "%~dp0..\x64\mediainfo.exe"=mediainfoalias (but this one doesnt work) and then use "alias" in FOR like: For /f "delims=" %%A in (' %mediainfoalias% --Infor... ?? – gamer0 May 24 '18 at 16:16
  • That's the wrong way around, try the above version, in the path's are no spaces or other prohibiting chars, so d'quoting isn't required here. – LotPings May 24 '18 at 16:18
  • yes, as you stated, only one pair of "" are processed, still even if this works as provided I am not happy with it, because this is a special case where I need to use "%~dp0..\..", so I will go with my own solution (provided below), however I am greatfull. – gamer0 May 25 '18 at 17:24
1

value=`http POST localhost:3000/test/login < test/login.json -h |awk ‘/Access-Token/{print $2}`

This will put the second value name Access token to a variable value

I guess awk is the best way to do what you are trying to cheers

0

unless there is a more "non-re-direct" way (?)...

@echo off

"%~dp0..\x64\mediainfo.exe" --Inform=General;%%UniqueID/String%% "%~dp0..\files\SOURCE.avi" > s.txt

set /p var=< s.txt

DEL /Q /F s.txt

echo=%var:~10,-5% | clip
gamer0
  • 945