# Creating new database from command line using \`fdbcli --exec\`

**URL:** <https://forums.foundationdb.org/t/creating-new-database-from-command-line-using-fdbcli-exec/1735>\
**Category:** Using FoundationDB\
**Created:** [November 14, 2019, 6:52pm UTC](https://forums.foundationdb.org/t/creating-new-database-from-command-line-using-fdbcli-exec/1735 "2019-11-14T18:52:06Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![kc626](https://avatars.discourse-cdn.com/v4/letter/k/4af34b/32.png) [@kc626](https://forums.foundationdb.org/u/kc626)\
**Post date:** [November 14, 2019, 6:52pm UTC](https://forums.foundationdb.org/t/creating-new-database-from-command-line-using-fdbcli-exec/1735/1 "2019-11-14T18:52:06Z")

</div>

I am currently writing up a program to install FDB client/server packages, extracting their files, and then running `fdbserver` and `fdbcli` binaries to start up a server and create a database (trying to do this all programmatically because I am using it as the setup for my java test environment which requires `foundationdb`).  
I have currently successfully managed to download the binaries and have been able to successfully run both `fdbserver` and `fdbcli` binaries. However, there seems to be something wrong when I try to create a new database by running `./fdbcli --exec "configure new single memory"`. The error message I get specifically is: `ERROR: Unknown command `configure new single memory’. Try `help'?`  
I initially that maybe the issue was related to `fdbcli` binary but I do not think this is the case because when I run `./fdbcli --exec "status"`, I get a correct response. Is there something I am doing wrong // is there some other way I can manage to create a new database programmatically?

---

<div class="post-metadata">

**Author:** ![markus.pilman](https://sea1.discourse-cdn.com/foundationdb/user_avatar/forums.foundationdb.org/markus.pilman/32/379_2.png) [@markus.pilman](https://forums.foundationdb.org/u/markus.pilman)\
**Post date:** [November 14, 2019, 6:59pm UTC](https://forums.foundationdb.org/t/creating-new-database-from-command-line-using-fdbcli-exec/1735/2 "2019-11-14T18:59:06Z")

</div>

This sounds like some escaping issue to me. Can you give us some more context on how you automate this? And can you post the relevant code that runs this command?

---

<div class="post-metadata">

**Author:** ![kc626](https://avatars.discourse-cdn.com/v4/letter/k/4af34b/32.png) [@kc626](https://forums.foundationdb.org/u/kc626)\
**Post date:** [November 14, 2019, 7:02pm UTC](https://forums.foundationdb.org/t/creating-new-database-from-command-line-using-fdbcli-exec/1735/3 "2019-11-14T19:02:52Z")

</div>

This is the code I am using to run the binaries:

```auto
    final CommandLine status = new CommandLine(fdbCliBinary.getAbsolutePath());
    status.addArgument("--exec");
    status.addArgument("\"status\"");
    executeCommand(status, true);

    final CommandLine configureDatabase = new CommandLine(fdbCliBinary.getAbsolutePath());
    configureDatabase.addArgument("--exec");
    configureDatabase.addArgument("\"configure new single memory\"");
    executeCommand(configureDatabase, true);

```

where `executeCommand` is as follows:

```auto
  private void executeCommand(final CommandLine command, final boolean shouldExecuteAsync) {
    LOGGER.warn("Running async: {}", String.join(" ", command.toStrings()));
    try {
      final ExecuteWatchdog watchdog = new ExecuteWatchdog(ExecuteWatchdog.INFINITE_TIMEOUT);
      final DefaultExecutor executor = new DefaultExecutor();
      executor.setWatchdog(watchdog);
      executor.setWorkingDirectory(foundationLocalDir);
      watchdogs.add(watchdog);
      LOGGER.warn("command: " + command.toString());
      if (shouldExecuteAsync) {
        // Using a result handler makes the command run async
        executor.execute(command, new DefaultExecuteResultHandler());
      } else {
        // Only passing in command makes the command run sync
        executor.execute(command);
      }
    } catch (Exception e) {
      LOGGER.warn("FAILED EXECUTE: " + e.getStackTrace());
    }
  }

```

Running the first `status` command returns a valid response but running the second `configure new single memory` command fails.

---

<div class="post-metadata">

**Author:** ![kc626](https://avatars.discourse-cdn.com/v4/letter/k/4af34b/32.png) [@kc626](https://forums.foundationdb.org/u/kc626)\
**Post date:** [November 14, 2019, 7:07pm UTC](https://forums.foundationdb.org/t/creating-new-database-from-command-line-using-fdbcli-exec/1735/4 "2019-11-14T19:07:32Z")

</div>

Here are the log statements that get printed as well in case it helps:  
`Running async: /Users/kevinchan/Documents/Courses/cs5152/geowave/test/./target/temp/fdb/fdbcli --exec status`

`Running async: /Users/kevinchan/Documents/Courses/cs5152/geowave/test/./target/temp/fdb/fdbcli --exec "configure new single memory"`

---

<div class="post-metadata">

**Author:** ![kc626](https://avatars.discourse-cdn.com/v4/letter/k/4af34b/32.png) [@kc626](https://forums.foundationdb.org/u/kc626)\
**Post date:** [November 14, 2019, 7:23pm UTC](https://forums.foundationdb.org/t/creating-new-database-from-command-line-using-fdbcli-exec/1735/5 "2019-11-14T19:23:55Z")

</div>

I just tried putting the command into a `configure-db.sh` file as follows:

```auto
#!/bin/sh
/Users/kevinchan/Documents/Courses/cs5152/geowave/test/./target/temp/fdb/fdbcli --exec "configure new single memory"

```

and then changing my code to run `configure-db.sh` instead and that seems to work so it seems like your hunch that it has to do with escaping characters seems to correct? Although I am not sure how I would fix my code.

---

<div class="post-metadata">

**Author:** ![markus.pilman](https://sea1.discourse-cdn.com/foundationdb/user_avatar/forums.foundationdb.org/markus.pilman/32/379_2.png) [@markus.pilman](https://forums.foundationdb.org/u/markus.pilman)\
**Post date:** [November 14, 2019, 7:47pm UTC](https://forums.foundationdb.org/t/creating-new-database-from-command-line-using-fdbcli-exec/1735/6 "2019-11-14T19:47:57Z")

</div>

> [@kc626](#):
>
> `configureDatabase.addArgument("\"configure new single memory\"");`

I think this is wrong. Can you try the following?

```auto
configureDatabase.addArgument("configure new single memory");

```

This being said, escaping rules usually confuse me. I would assume that the `addArgument` method does some automatic escaping for you and so your additional escaping is then carried over to fdbcli (and so fdbcli thinks that you want to have this as one token).

---

<div class="post-metadata">

**Author:** ![kc626](https://avatars.discourse-cdn.com/v4/letter/k/4af34b/32.png) [@kc626](https://forums.foundationdb.org/u/kc626)\
**Post date:** [November 14, 2019, 8:16pm UTC](https://forums.foundationdb.org/t/creating-new-database-from-command-line-using-fdbcli-exec/1735/7 "2019-11-14T20:16:13Z")

</div>

I tried changing it to that but I get the same error

---

<div class="post-metadata">

**Author:** ![kc626](https://avatars.discourse-cdn.com/v4/letter/k/4af34b/32.png) [@kc626](https://forums.foundationdb.org/u/kc626)\
**Post date:** [November 14, 2019, 8:53pm UTC](https://forums.foundationdb.org/t/creating-new-database-from-command-line-using-fdbcli-exec/1735/8 "2019-11-14T20:53:04Z")

</div>

Oh I figured it out! `addArgument` as an optional field called `handleQuoting` which defaults to `true`. I just called:

```auto
configureDatabase.addArgument("configure new single memory", false);

```

and it worked! Thanks so much for the help!
