Using spaces in the command line mode

Any question about the main GUI application (frontend)
Post Reply
klift
Posts: 2
Joined: Fri Jan 27, 2023 4:06 pm

Using spaces in the command line mode

Post by klift »

Hello,

I am currently working on writing a command line script to convert a batch of .laz files to .e57 format and it seems to work in most of cases.

Code: Select all

set local EnableDelayedExpansion

REM specify the directory with the .laz files for the format change
set Files2Convert="D:\in"

REM specifying the directory where the converted files must be saved
set Output="D:\out"

REM cycling through all files within the Files2Convert directory and applying "Convert" function
for %%f in ( "%Files2Convert%"\* ) do (call :Convert "%%f")
pause

:Convert
REM extracting the filename with the file format
set filename="%~nx1"

REM removing all spaces from the name
set filename=%filename: =%

REM creating a saving path and changing the format
set savepath="%Output:~1,-1%\%filename:~1,-1%"
set savepath=%savepath:.laz=.e57%

REM calling the cloudcompare executable
"C:\Program Files\CloudCompare\cloudcompare.exe" -SILENT -AUTO_SAVE OFF -O %1  -C_EXPORT_FMT E57 -SAVE_CLOUDS FILE %savepath%
:End
The problem I have is related to the directories with spaces in their names. Due to the spaces, CloudCompare assumes that there are multiple clouds to save and it causes an error. Is there a way to handle the spaces in specified paths except for just not using those paths? And is there a better way to convert multiple .laz files to .e57?
daniel
Site Admin
Posts: 7707
Joined: Wed Oct 13, 2010 7:34 am
Location: Grenoble, France
Contact:

Re: Using spaces in the command line mode

Post by daniel »

Daniel, CloudCompare admin
klift
Posts: 2
Joined: Fri Jan 27, 2023 4:06 pm

Re: Using spaces in the command line mode

Post by klift »

daniel wrote: Sat Jan 28, 2023 8:28 am I think this should help you: https://www.cloudcompare.org/forum/view ... 18&p=27109
Thank you, I have checked the link. It indeed solves the problem of just having paths with spaces in cmd. I had this problem initially as well and I also solved it by using quotes. However, it doesn't help when the command -SAVE_CLOUDS is used. I use it along with the option FILE in order to save the output in a different specified directory.

Perhaps, it is not the intended use of this option, since CloudCompare wiki states that this option allows the user to specify the output filename(s) of the clouds (FILE "file1.xxx file2.yyy ...") and nothing is said about saving files in different directories. Although, if a path is specified along with the filename, it saves the output in a different directory. It will work, given that the output path doesn't have any spaces, otherwise CloudCompare will assume it is a separator, which separates two different filenames for two different clouds (just like in the example FILE "file1.xxx file2.yyy ..."), which will cause an error. Is there a way to overcome it or currently the only solution is to use paths without spaces?
daniel
Site Admin
Posts: 7707
Joined: Wed Oct 13, 2010 7:34 am
Location: Grenoble, France
Contact:

Re: Using spaces in the command line mode

Post by daniel »

Ah, indeed, we may have an issue differentiating paths with spaces and arguments... We'll have to take care of that globally I believe. For now you'll have to use paths without spaces, but it should be fixed soon (hopefully).
Daniel, CloudCompare admin
daniel
Site Admin
Posts: 7707
Joined: Wed Oct 13, 2010 7:34 am
Location: Grenoble, France
Contact:

Re: Using spaces in the command line mode

Post by daniel »

Ok, this should be fixed now (with the 2.13.alpha version from today).

You can use either double or single quotes for filename (or scalar field names) with spaces.
Daniel, CloudCompare admin
SeaTea
Posts: 4
Joined: Fri Oct 28, 2022 12:13 pm

Re: Using spaces in the command line mode

Post by SeaTea »

daniel wrote: Sun Feb 12, 2023 9:36 pm Ok, this should be fixed now (with the 2.13.alpha version from today).

You can use either double or single quotes for filename (or scalar field names) with spaces.

This does not appear to be working. I'm using the latest 2.13 Alpha version (installed last week). The files are dragged and dropped onto the batch file.

I have a simple command line batch that takes the input file and applies a SOR filter before saving it as the original filename with an appended string at the end. This works perfectly for all filenames without spaces but not for any name containing a space. It throws an error with the number of clouds it wants to save is relative to the number of spaces in the filename. eg. Invalid parameter: specified 3 file names, but there are 1 clouds.

The bat file looks like this

Code: Select all

pushd "%~dp1"
"C:\Program Files\CloudCompare\cloudcompare.exe" -O "%~1" -AUTO_SAVE OFF -SOR 8 2 -C_EXPORT_FMT LAS -EXT LAZ -SAVE_CLOUDS FILE "%~n1_Only_SOR%~x1"
popd
daniel
Site Admin
Posts: 7707
Joined: Wed Oct 13, 2010 7:34 am
Location: Grenoble, France
Contact:

Re: Using spaces in the command line mode

Post by daniel »

Your script works well on my side (with the latest 2.13.alpha version).

Could it be that you have space characters or other special characters in the filename?

What does the command look like when you drop the file on your batch file?

On my side I have:

Code: Select all

"C:\Program Files\CloudCompare\cloudcompare.exe" -O "F:\Data\LAS\u4625640_12-06-23_allclasses_fence.las" -AUTO_SAVE OFF -SOR 8 2 -C_EXPORT_FMT LAS -EXT LAZ -SAVE_CLOUDS FILE "u4625640_12-06-23_allclasses_fence_Only_SOR.las"
Daniel, CloudCompare admin
SeaTea
Posts: 4
Joined: Fri Oct 28, 2022 12:13 pm

Re: Using spaces in the command line mode

Post by SeaTea »

daniel wrote: Sun May 14, 2023 12:13 pm Your script works well on my side (with the latest 2.13.alpha version).

Could it be that you have space characters or other special characters in the filename?

What does the command look like when you drop the file on your batch file?

On my side I have:

Code: Select all

"C:\Program Files\CloudCompare\cloudcompare.exe" -O "F:\Data\LAS\u4625640_12-06-23_allclasses_fence.las" -AUTO_SAVE OFF -SOR 8 2 -C_EXPORT_FMT LAS -EXT LAZ -SAVE_CLOUDS FILE "u4625640_12-06-23_allclasses_fence_Only_SOR.las"
Hi Daniel. Yes, as I mentioned in my previous post, this does work for filenames that do not have any spaces in them. If the filename has any spaces, it returns an error. I possibly misread but I thought 2.1.3 Alpha had fixed it so that it would allow spaces in the file name. I have the output filename inside inverted commas "" so that it should treat it as a complete string but CloudCompare won't write the filename out if there are spaces.
SeaTea
Posts: 4
Joined: Fri Oct 28, 2022 12:13 pm

Re: Using spaces in the command line mode

Post by SeaTea »

SeaTea wrote: Mon May 15, 2023 6:40 am
daniel wrote: Sun May 14, 2023 12:13 pm Your script works well on my side (with the latest 2.13.alpha version).

Could it be that you have space characters or other special characters in the filename?

What does the command look like when you drop the file on your batch file?

On my side I have:

Code: Select all

"C:\Program Files\CloudCompare\cloudcompare.exe" -O "F:\Data\LAS\u4625640_12-06-23_allclasses_fence.las" -AUTO_SAVE OFF -SOR 8 2 -C_EXPORT_FMT LAS -EXT LAZ -SAVE_CLOUDS FILE "u4625640_12-06-23_allclasses_fence_Only_SOR.las"
Hi Daniel. Yes, as I mentioned in my previous post, this does work for filenames that do not have any spaces in them. If the filename has any spaces, it returns an error. I possibly misread but I thought 2.1.3 Alpha had fixed it so that it would allow spaces in the file name. I have the output filename inside inverted commas "" so that it should treat it as a complete string but CloudCompare won't write the filename out if there are spaces.
OK, I managed to fix the issue by putting the output string inside single and then double quotation marks ' " (with no space).
'"%~n1_SOR%~x1"'

Code: Select all

pushd "%~dp1"
"C:\Program Files\CloudCompare\cloudcompare.exe" -O "%~1" -AUTO_SAVE OFF -SET_ACTIVE_SF Range -FILTER_SF 1.5 35 -SET_ACTIVE_SF Intensity -FILTER_SF 1 255 -SOR 8 2 -C_EXPORT_FMT LAS -EXT LAZ -SAVE_CLOUDS FILE '"%~n1_SOR%~x1"'
popd
Theresa76
Posts: 1
Joined: Fri Dec 15, 2023 11:07 am

Re: Using spaces in the command line mode

Post by Theresa76 »

SeaTea wrote: Mon May 15, 2023 6:40 am
daniel wrote: Sun May 14, 2023 12:13 pm Your script works well on my side (with the latest 2.13.alpha version).

Could it be that you have space characters or other special characters in the filename?

What does the command look like when you drop the file on your batch file?

On my side I have:

Code: Select all

"C:\Program Files\CloudCompare\cloudcompare.exe" -O "F:\Data\LAS\u4625640_12-06-23_allclasses_fence.las" -AUTO_SAVE OFF -SOR 8 2 -C_EXPORT_FMT LAS -EXT LAZ -SAVE_CLOUDS FILE "u4625640_12-06-23_allclasses_fence_Only_SOR.las"
Hi Daniel. Yes, as I mentioned in my previous post, this does work for filenames that do not have any spaces in them. If the filename has any spaces, it returns an error. I possibly misread but I thought 2.1.3 Alpha had fixed it so that it would allow spaces in the file name. I have the output filename inside inverted commas "" so that it should treat it as a complete string but CloudCompare won't write the filename out if there are spaces.
Thanks for the information!
Post Reply