Search code examples
qtqmake

QMake - Erratic behaviour When using echo System Command


Using QMake, I read some boiler plate code, make modifications and write the modified code to a file. However, I get very strange results. I have simplified the problem down to the following:

# Open boiler plate file
interfaceBoilerPlateCode = $$cat($$boilerPlateFile, blob)

# Make sure we read the right content
message("Content read: $$interfaceBoilerPlateCode")

# Write the read text into a file
output = $$system(echo $$interfaceBoilerPlateCode >> $$targetFile) # Doesnt work
output = $$system(echo "Howde" >> $$targetFile) # This works

The file being read is a plain text file containing only the string "Howde". The contents of the file get read correctly.

However, when I try and write the contents of the file to another target file, I get no output (literally: no errors/warnings but no new file generated). However, if I use echo with just a string defined in the code itself (as in the last line of snippet above), a new file gets generated with the string "Howde" inside it.

What is going on? What am I doing wrong that the penultimate line does not generate a new file?


Solution

  • Use write_file. Instead of:

    $$system(echo $$content >> $$file_path)
    

    use

    write_file($$file_path, $$content)