0

I want to edit a file; it's the chromedriver.exe. The problem is that when I write this command:

perl -pi -e 's/cdc_/dog_/g' /path/to/chromedriver

It replies: "No such file or directory."

Where must I place my file, or how can I edit it?

brian d foy
  • 129,424
  • 31
  • 207
  • 592
User58
  • 17
  • 5
  • 7
    You're on Windows. You need to use a Windows path, eg. `C:\path\to\chromedriver`. Second, `/path/to/chromedriver` is an example. You need to replace it with the real path to `chromedriver` on your system. Third, on Windows, you'll probably need to add an `.exe` extension to the filename. – stevieb May 20 '22 at 17:52
  • 2
    Since this is windows you need double quotes around your code after the '-e'. – FractalLotus May 20 '22 at 18:01
  • 2
    I find it highly unlikely that you would be able to successfully in-place edit a Windows executable with a Perl one-liner. If anything, you would probably just corrupt the file and make it unusable. – TLP May 20 '22 at 21:23

1 Answers1

5

You mentioned that you want to edit chromedriver.exe, but your command was:

perl -pi -e "s/cdc_/dog_/g" /path/to/chromedriver

Instead, use:

perl -pi -e "s/cdc_/dog_/g" /path/to/chromedriver.exe
# see the difference starting here --------------^

... to match the actual filename. Be sure to back up the original file if it's not easily recoverable!

As a side note, I found this similar question from Jun 26, 2021 that pointed to a comment:

Ok, I reinstalled Chrome WebDriver, did NOT run the Perl script, instead ran hex editor and everything works now. Devs, don't make the same mistake as me of running that script; I have no idea what's wrong with it and have no time to check, but it didn't work. Find+Replace in Hex Editor instead!

As a second side note, Kyle made a comment that points out an important point:

Keep the $ mark and don't change the length of the key, and you'll be fine

I noticed that your perl script doesn't require a leading $, so without being sure what you're trying to replace, I might suggest:

perl -pi -e "s/\$cdc_/\$dog_/g" /path/to/chromedriver.exe

ikegami pointed out that editing a binary file may corrupt it by adding carriage returns to each line. They suggest adding binmode to the input and output streams:

perl -pi -e "BEGIN { binmode STDIN; binmode STDOUT } s/\$cdc_/\$dog_/g" /path/to/chromedriver.exe
Jeff Schaller
  • 2,352
  • 5
  • 23
  • 38
  • 2
    Re "*I have no idea what's wrong with it*", This will turn 0A into 0D 0A, breaking the binary. Add `BEGIN { binmode STDOUT }`, and you might have to avoid `-i`. – ikegami May 20 '22 at 19:43
  • 1
    Interesting; thanks, @ikegami! I assumed, after finding the second link, that it was corrupting other `cdc_` sections that weren't `$cdc_`. I'll make the update you suggested. – Jeff Schaller May 20 '22 at 19:46
  • in my case, it still doesn't work, I always get an error message telling me that the file is corrupt. – User58 May 20 '22 at 20:42
  • Sorry to hear that, @User58! I've linked a few posts with lots of discussion around it, as well as ikegami's recent comment. Hopefully you'll find a solution to the corruption. – Jeff Schaller May 20 '22 at 20:49
  • oh, right, it's not enough. You would need to binmode the input too – ikegami May 20 '22 at 21:23
  • @ikegami please feel free to edit the post to make improvements; I'm not in a place right now where I can experiment with it. Thank you! – Jeff Schaller May 20 '22 at 21:31