question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

replace_in_file() failed on Windows

See original GitHub issue

See: https://github.com/inexorgame/inexor-core/issues/589

If the searched string is multi-line, replace_in_file(file_path, search, replace, strict=True) will fail on Windows.

tools.replace_in_file(cmake_name, '''  11111
    2222''', '''  3333''')
ConanException: replace_in_file didn't find pattern

The reason is “\r\n” and “\n” mismatch.

λ conan --version
Conan version 1.2.1

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:10 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
HassanNawazish1commented, Aug 16, 2021

Thanks. I was using the “PROJECT” instead of “project”. It worked now.

1reaction
lasotecommented, Apr 7, 2018

Yes, the replace_in_file is literally looking for the string so a \n != \r\n. Try to replace line by line doing two “replace_in_file” or build a string to be replaced with os.linesep, something like:

tools.replace_in_file(cmake_name, ''' 11111%s 2222''' % os.linesep, ''' 3333''')

Read more comments on GitHub >

github_iconTop Results From Across the Web

System restore failed to replace the file - Microsoft Community
Hi Tried to do restore operation on windows 10 on previous restore points but it fails with same error for every instance of...
Read more >
replace-in-file - npm
A simple utility to quickly replace text in one or more files or globs. Works synchronously or asynchronously with either promises or callbacks....
Read more >
R News - The Comprehensive R Archive Network
R CMD INSTALL and install.packages() on Windows are now more robust against a locked file in an earlier installation of the package to...
Read more >
Replace all instances of a particular string in a file using a ...
This option allows Ansible to fall back to unsafe methods of updating filesystem objects when atomic operations fail (however, it doesn't force Ansible...
Read more >
windows/shell.exec: Open a File or URL using ... - Rdrr.io
Encoded file:// URLs should be in the Windows standard form, e.g. "file:///c:/path/to/file.txt" . Value. No value, but informative error messages will be given ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found