0

I'm trying to execute a series of Cypher queries using Cypher shell according to here. I have created a file called "cypher.ex1" and placed it into import and bin folder. Here is its content:

MATCH (n) RETURN n;

MATCH (batman:Person {name: 'Bruce Wayne'}) RETURN batman;

I'm trying to execute it using:

$neo4j-home> cat cypher.ex1 | bin/cypher-shell -u neo4j -p 123456 --format plain

but when I run this, nothing happens and after waiting for a long time with no output, I need to press "CTRL + C" to terminate the command. Here is an screenshot of the problem:

enter image description here

In fact, cypher-shell works fine for one line commands, but not for scripts. What's wrong?

cybersam
  • 63,203
  • 6
  • 53
  • 76
Pablo
  • 465
  • 1
  • 4
  • 14

1 Answers1

1

You are trying to execute this command line:

cat cypher.ex1 | bin/cypher.shell -u neo4j - 123456

from within the cypher.shell environment. That will not work, since cypher.shell only supports Cypher statements and a limited set of commands (use the :help command to see what is available).

The reason nothing happened for you (not even an error) is because cypher.shell did not see a colon (':') at the start of your command line, so it assumed that you were entering a Cypher statement and was waiting (forever) for the ending semicolon (';') before parsing it.

If you want to execute that exact command line, you have to execute it outside of cypher-shell (when it is not running).

However, if you really do want to perform the equivalent action from within the cypher.shell environment, you can use its :source command. For example:

:source cypher.ex1

The default location for the source file is the "current working directory", which is the directory you were in when you launched cypher.shell. If the file is elsewhere, you can specify the relative path of the file from the current working directory as the :source argument.

cybersam
  • 63,203
  • 6
  • 53
  • 76
  • After executing ":source cypher.ex1", this came up: Cannot find file: 'cypher.ex1' Where should I put the "cypher.ex1"? – Pablo Feb 15 '20 at 07:56
  • By default, the "current working directory", which is the directory you were in when you launched `cypher.shell`. If the file is not there, the `:source` argument can be a relative path from that directory. I have added this info to my answer. – cybersam Feb 15 '20 at 09:45