Cmake error: Invalid escape sequence \U - path

While running my OpenCL code in VC++ 10 by using CMake I am getting the following error:
CMake Error at CMakeLists.txt:6 (set): Syntax error in cmake code at
C:/Users/Shreedhar/Desktop/testCL/CMakeLists.txt:6
when parsing string
C:\Users\Shreedhar\Desktop\test_CL\CMakeLists
Invalid escape sequence \U

Use forward slashes / in your paths
C:/Users/Shreedhar/Desktop/test_CL/CMakeLists

If you are reading user input like environment variables then you'll need to do this by character replacement feature of string method.
string(REPLACE "\\" "/" outputVar ${_inputVar})

For those who receive this error under Windows:
CMake Error at
C:/Dev/cmake/share/cmake-3.8/Modules/FindBoost.cmake:903 (list):
Syntax error in cmake code at
C:/Dev/cmake/share/cmake-3.8/Modules/FindBoost.cmake:903
when parsing string
C:\Dev\mongodb\src\boost/lib${_arch_suffix}-msvc-15.0
Invalid character escape '\D'. Call Stack (most recent call first):
C:/Dev/cmake/share/cmake-3.8/Modules/FindBoost.cmake:1379
(_Boost_UPDATE_WINDOWS_LIBRARY_SEARCH_DIRS_WITH_PREBUILT_PATHS)
src/bsoncxx/CMakeLists.txt:100 (find_package)
Don't set the BOOST_ROOT environment variable to a backslash-ended value.

Related

Python Getting a SyntaxError: parsing command to Hython on windows

I'm trying to parse a few commands to Houdini's Python module called Hython.
And I'm doing this through os on windows.
My command looks like this:
command = '''"c:\\Program Files (x86)\\Steam\\steamapps\\common\\Houdini Indie\\bin\\hython.exe" -c \
"import sys; sys.path.append('d:\\Cloud\\OneDrive\\Dokumenter\\GitHub\\tutorialTools\\utils'); \
import houUtils; houUtils.runReduction(\'%s\',\'%s\')"''' % (assetDir, amount)
os.popen(command)
I've tried all the tricks on quotations I could think of, but I'm getting a :
SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes
in position 49-50: truncated \uXXXX escape
Any kind of help would be appreciated
First I tried adding to the command by separate lines:
"command +=" but this stopped me quickly.
I've tried doing the initial path with r'c:\...'
The entire problem seems to be connected with writing paths inside a quotation.

Error "tar: Invalid transform expression"while I am creating a TAR using system command in ruby. Why?

I am creating a TAR using system command in ruby, passing a array as argument
which look likes this:
cmd_params = ["tar", "-cf", "my.tar", "wp-signup.php_1433243457_25152", "--transform='s/_[0-9]*_[0-9]*$//g'"]
system(*cmd_params)
But getting an Error
tar: Invalid transform expression
is there any way out for doing this ??
The single quotes are needed on the command line or in a shell script to prevent the shell from interpreting the special characters. They're not needed here.

Lua - popen command with multiple double quotes

I am writing a Lua script to manage Virtualbox on windows.
It seems that multiple double quotes are not parsed correctly. I am using the following function to implement this:
--Get output from an OS command - http://stackoverflow.com/questions/132397/get-back-the-output-of-os-execute-in-lua
function os.capture(cmd, raw)
local f = assert(io.popen(cmd, 'r'))
local s = assert(f:read('*a'))
f:close()
if raw then return s end
s = string.gsub(s, '^%s+', '')
s = string.gsub(s, '%s+$', '')
s = string.gsub(s, '[\n\r]+', ' ')
return s
end
This code works so long an the machine name doesn't have a space, but machines can have spaces so I have to support them:
local command = '"\\Program Files\\Oracle\\VirtualBox\\VBoxManage\" showvminfo '..key
The following code does not work at all but it does give the correct format of the command to the log file so the syntax should be correct:
local command = '"\\Program Files\\Oracle\\VirtualBox\\VBoxManage\" showvminfo "'..key..'"'
logger:write("[",os.date("%Y-%m-%d %H:%M:%S"),"] Command: ",command,"\n")
vmStateRaw = os.capture(command, "raw")
Log file entry:
[2014-12-06 16:09:18] Command: "\Program Files\Oracle\VirtualBox\VBoxManage" showvminfo "Cerium"
Interpreter output:
'\Program' is not recognized as an internal or external command,
operable program or batch file.
I have found that the following syntax works:
local command = '""\\Program Files\\Oracle\\VirtualBox\\VBoxManage\" showvminfo "'..key..'"'
Log file output:
[2014-12-06 16:27:54] Command: ""\Program Files\Oracle\VirtualBox\VBoxManage" showvminfo "Cerium"
So this question isn't to solve a problem as I have aleady done that. I want to understand why the last command works as my current understand means this should not work.
TIA
The issue has to do with how system in C works. Under windows, system internally calls
cmd /c yourinput
Since os.execute just delegates to system (see here), your command likely ends up executing as:
cmd /c "\Program Files\Oracle\VirtualBox\VBoxManage" showvminfo "Cerium"
For reference, from help cmd:
If /C or /K is specified, then the remainder of the command line after
the switch is processed as a command line, where the following logic is
used to process quote (") characters:
If all of the following conditions are met, then quote characters
on the command line are preserved:
no /S switch
exactly two quote characters
no special characters between the two quote characters,
where special is one of: &<>()#^|
there are one or more whitespace characters between the
two quote characters
the string between the two quote characters is the name
of an executable file.
Otherwise, old behavior is to see if the first character is
a quote character and if so, strip the leading character and
remove the last quote character on the command line, preserving
any text after the last quote character.
Since your command contains 4 double quotes in there, it parses your command with the old behavior. This is why you need to surround your entire command with an extra set of " double quotes.

CMake how to remove the path from compile errors

When using cmake if there is a compile error the error is output with the entire path to the file containing the error. This path can be very long (see example below) so often it word wraps and makes it difficult to read.
Example Output:
/home/nick/projects/projectA/src/environment/base/terrain/base/TestFile.h:21:37: error: ‘TestFile’ does not name a type
/home/nick/projects/projectA/src/environment/base/terrain/base/TestFile.h:21:54: error: expected unqualified-id before ‘test’
/home/nick/projects/projectA/src/environment/base/terrain/base/TestFile.h:21:54: error: expected ‘)’ before ‘test’
Is there a way to remove the path from the error?
Something like this:
TestFile.h:21:37: error: ‘TestFile’ does not name a type
TestFile.h:21:54: error: expected unqualified-id before ‘test’
TestFile.h:21:54: error: expected ‘)’ before ‘test’
Thanks
I don't know if it is possible within cmake, but you can always redirect stderr to stdout and filter the output with a short sed script. At least the common project path can be filtered
make 2>&1 | sed 's/\/home\/nick\/projects\/projectA\/src\///g'

javac flag to print only the error locations

Is it possible to make javac output only the error locations and the error messages, and hide the source code dump?
Now I get:
$ javac t.java
t.java:1: <identifier> expected
class {
^
t.java:2: reached end of file while parsing
bar
^
t.java:4: reached end of file while parsing
^
3 errors
I want to get only:
$ javac ... t.java
t.java:1: <identifier> expected
t.java:2: reached end of file while parsing
t.java:4: reached end of file while parsing
I think there is no flag you could pass to javac, but you can simply filter the output through any program which removes the superfluous lines. Here an example with grep:
javac t.java 2>&1 | egrep '^[a-zA-Z0-9_/]+\.java:[0-9]+: '
You might have to change the part matching the file name if you have strange letters in your file name - this seems to work for the ASCII subset.

Resources