0

I have a run.sh which takes 2 parameters, one MP4 file and many CSV files, works perfectly on Linux.

#!/bin/sh
chmod +x my_py_script.py
./my_py_script.py ./mp4/my_video.mp4 ./csv/*.csv

But when I convert it to work on Windows with this batch script:

@echo off
setlocal enableDelayedExpansion 

set MYDIR=D:\my_folder_path\csv
for /f %%i in ('dir /B/D %MYDIR%') DO call :concat %%i
python "D:\my_folder_path\my_python_script.py" "D:\my_folder_path\mp4\my_mp4_file.mp4" %myvar%
goto :eof

:concat
set myvar=%myvar% %MYDIR%\%1
goto :eof

It throws an error that parameter is too long. I have about 30,000 CSV files in CSV folder.

How can I fix it?

Mofi
  • 46,139
  • 17
  • 80
  • 143
Luke
  • 1,623
  • 3
  • 24
  • 32
  • 1
    [On computers running Microsoft Windows XP or later, the maximum length of the string that you can use at the command prompt is 8191 characters.](https://stackoverflow.com/q/3205027/995714). Why don't just put the file list in a file? – phuclv Nov 09 '17 at 06:59
  • 1
    There is no chance to pass such a long list of files to any application on Windows. The length of an environment variable `name + equal sign + string + terminating null` is limited to 8192 characters and maximum command line length is also limited. If you search for the environment variables length limit and the Windows command line limit in WWW, you will surely find them. I suggest to rewrite the Python script to support an option to specify a list file containing line by line the file names (with relative or absolute path) to process by the Python script. – Mofi Nov 09 '17 at 06:59
  • 1
    [the limit on Linux is much longer](https://stackoverflow.com/q/19354870/995714) – phuclv Nov 09 '17 at 07:02
  • Thanks for quick reply! @LưuVĩnhPhúc The coding logic in .py file loops through arguments and process it, so if I need to change batch script I must edit the python code, it has come from customer so it's difficult for me to change script. Anyways, I will talk with customer about this. – Luke Nov 09 '17 at 07:09
  • thanks @Mofi for English edit too! – Luke Nov 09 '17 at 07:17
  • @LongTTH As it looks like the Python script should always process all *.csv files in a directory, it would be alternatively a good idea to ask for a Python script option to specify as parameter a directory with CSV files and the Python script itself searches in specified directory for the *.csv files and process them. – Mofi Nov 09 '17 at 07:20
  • Not understanding why you can specify `*.csv` to the python script running on Linux but you cannot do the same for the Windows version? – Squashman Nov 09 '17 at 17:30
  • @Squashman : in linux, my customer just pass all 1000 csv file names to command line parameter and loop through it in python code, in windows, when I pass 1000 csv file name to command line parameter, it's overloaded. – Luke Nov 13 '17 at 14:14
  • @LongTTH, so your code example is incorrect. – Squashman Nov 13 '17 at 14:41

0 Answers0