replace_in_file() failed on Windows
See original GitHub issueSee: 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:
- Created 5 years ago
- Comments:10 (8 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Thanks. I was using the “PROJECT” instead of “project”. It worked now.
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 withos.linesep
, something like:tools.replace_in_file(cmake_name, ''' 11111%s 2222''' % os.linesep, ''' 3333''')