2

So I have this function, which I use to launch urls in Brave Browser. I would like to be able to use the --profile-directory switch to launch my urls in specific profiles, but Dart treats the quotes in my argument differently. Here is the command I want to execute:

start brave --profile-directory="Profile 1" "https://example.com"

The Dart code is this:

Process.run(
  "start",
  [
    'brave',
    '--profile-directory="Profile 1"',
    url,
  ],
  runInShell: true,
);

However, it replaces my double quotes with a "\". I'm greeted with an error dialog that says "Windows cannot find 1\" ". Make sure you typed the name correctly, and then try again.

I tried escaping them by using '\"Profile 1\"' but that didn't help either. This was the case for a while, but now theres something unusual happening. The same command launches Brave in the Profile select window, asking me to choose a profile.

I also tried passing the arguments like this : ['brave', '--profile-directory', '"Profile 1"']. This command doesn't even launch brave.

How do I properly execute said command using Process.run()? I'm using Flutter for Windows.

Unmitigated
  • 76,500
  • 11
  • 62
  • 80
  • 1
    Windows' `start` command is [notorious for doing weird things with quoted arguments](https://stackoverflow.com/questions/154075/using-the-start-command-with-parameters-passed-to-the-started-program). Do you need to use it? Can you try running `brave.exe` directly to eliminate any potential weirdness from `start`? – jamesdlin Feb 06 '21 at 05:49
  • @jamesdlin i did try using the whole path to "brave.exe". It does pretty much the same thing. The problem lies in how dart passes my argument to the cmd shell. It appends a "\" to every double quote character which messes up the actual code. – veryepicdude Feb 06 '21 at 11:42
  • Nevermind, passing the argument directly in the command fixed the issue. Thanks a lot for suggesting against using the start command :) – veryepicdude Feb 06 '21 at 12:00

1 Answers1

0

Found solution:

Not using the start command and runInShell and using the direct exe reference to directly pass the argument in the executable fixed the issue.

Process.run(
    'C:\\Program Files\\BraveSoftware\\Brave-Browser\\Application\\brave.exe --profile-directory="Profile 1"',
    [url]);