Ryza Jr.
Ryza Jr.

Reputation: 105

How to Bypass Character Limit When Using CMD /c?

I'm writing a command line batch script in Windows 7 to upload multiple images for hosting, paste the url (using this program) and filename into a line of text, then append the text to a file.

The following code gives me an error because the command "cmd /c" is too long.

@echo on
set DIR1="C:\Users\My\Desktop\temp"
set DIR2="C:\Misc\Programs\EasyImgur"
set DIR3="C:\Users\My\Desktop"

set DIR2=%DIR2:"=%
set DIR3=%DIR3:"=%

forfiles /m *.png /p %DIR1% /c "cmd /c %DIR2%\EasyImgur.exe /anonymous @path && timeout /t 2 /nobreak > NUL && paste > %DIR3%\temp.txt && set /p URL= < %DIR3%\temp.txt && echo if(G9="@fname",IMAGE(%URL%,3), >> %DIR3%\test.txt"

del %DIR3%\temp.txt

pause
exit

Is there any way around this? Some way to call all that text after "cmd /c" without breaking the character limit? I need all that done for every file in the directory.

Thanks in advance.

Upvotes: 1

Views: 1868

Answers (2)

Ryza Jr.
Ryza Jr.

Reputation: 105

Thanks to Harry Johnston's help, I got it! Check it out.

The code is:

@echo off

setlocal EnableDelayedExpansion

set "DIR1=C:\Users\RyzaJr\Desktop\temp"
set "DIR2=C:\Misc\Programs\EasyImgur"

for %%a in (%DIR1%\*.png) do (

    "%DIR2%\EasyImgur.exe" /anonymous "%%a"
    timeout /t 4 /nobreak > NUL
    paste > temp.txt
    set /p URL= < temp.txt
    echo if(G11="%%~na",IMAGE(!URL!,3^), >> "output.txt"

)

del temp.txt
exit

Upvotes: 1

foxidrive
foxidrive

Reputation: 41244

This might work for you - the term you echo into the file has mismatched parenthesis though.

@echo on
set "DIR1=C:\Users\My\Desktop\temp"
set "DIR2=C:\Misc\Programs\EasyImgur"
set "DIR3=C:\Users\My\Desktop"

for %%a in ("%DIR1%\*.png") do (
  start "" /w /b "%DIR2%\EasyImgur.exe" /anonymous "%%a"
  set "flag="
   for /f "delims=" %%b in ('paste') do (
     if not defined flag >>"%DIR3%\test.txt" echo if(G9="%%~na",IMAGE(%%b,3^),
     set flag=1
   )
)
pause

Upvotes: 0

Related Questions