Answers.Body: <p>This is because there are not assemblies for <em>Crepis commutate</em> within NCBI's assembly database.</p>
  <p>The cross check is here:</p>
  <p><a href="https://www.ncbi.nlm.nih.gov/assembly/?term=Crepis%20commutata" rel="nofollow noreferrer">https://www.ncbi.nlm.nih.gov/assembly/?term=Crepis+commutata</a></p>
  <p>The output is a bit clearer than Entrez</p>
  <blockquote>
  <p>The following terms were not found in Assembly: commutata, Crepis commutata[All Fields].
  No items found.</p>
  </blockquote>
  <p>All you need do to correct it is issue a <code>next</code> statement in the a loop of species above the code you've presented.</p>
  <pre><code>if [[ &quot;<span class="math-container">$species" == 'Crepis commutata' ]]; then
    continue
  fi
  esearch -db assembly -query "$</span>species&quot; | xtract -pattern ENTREZ_DIRECT -element Count
  </code></pre>
  <hr />
  <p>To answer the comments if this is done via a Python subprocess, you could simply issue the following code (which has not been checked)</p>
  <pre><code>import subprocess
  
  for species in List:
      try:
          subprocess.run([&quot;esearch&quot;, &quot;-db&quot; &quot;assembly&quot;, &quot;-query&quot;, f&quot;${species}&quot;, &quot;|&quot;, &quot;xtract&quot;, &quot;-pattern&quot;, &quot;ENTREZ_DIRECT&quot;, &quot;-&quot;, &quot;element&quot;], shell=True&quot;)
      except ValueError as ve:
          print(f'Species {species}, is not present.')
          continue
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2023-01-27T19:38:20.867Z
Answers.Text: Right but is there a way to set `entrez` tools to pipe the error? Being able to do that would help me clean up the output produced from an automated session a bit easier. **Crepis commutate** no existing on NCBI is not the issue, rather not being able to cleanly pipe the outcome is the issue.
Answers.UserDisplayName: Sudoh
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2023-01-27T23:35:34.670Z
Answers.Text: 2>&1      Merge stderr into stdout ; https://stackoverflow.com/questions/818255/what-does-21-mean
Answers.UserDisplayName: pippo1980
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2023-01-27T19:34:02.930Z
Answers.LastActivityDate: 2023-01-27T20:34:21.710Z
Answers.LastEditDate: 2023-01-27T20:34:21.710Z
Answers.UserDisplayName: M__
Body: <p>I am using the following one-liner with <code>NCBI entrez</code> to query their databases from the terminal (see <a href="https://www.ncbi.nlm.nih.gov/books/NBK179288/" rel="nofollow noreferrer">Entrez Direct: E-utilities on the Unix Command Line</a>:</p>
  <pre><code>esearch -db assembly -query ${species name} |
      xtract -pattern ENTREZ_DIRECT -element Count
  </code></pre>
  <p>This works a charm but occasionally it sends an xml error that messes up the output.</p>
  <p>Here is an example of the error:</p>
  <pre><code>xml
  FAILURE ( Fri Jan 27 01:12:44 PM CST 2023 )
  nquire -url https://eutils.ncbi.nlm.nih.gov/entrez/eutils/ esearch.fcgi -retmax 0 -usehistory y -db assembly -term &quot;Crepis commutata&quot; -tool edirect -edirect 18.7 -edirect_os Linux -email {}
  &lt;ErrorList&gt;
    &lt;PhraseNotFound&gt;commutata&lt;/PhraseNotFound&gt;
    &lt;PhraseNotFound&gt;Crepis commutata[All Fields]&lt;/PhraseNotFound&gt;
  &lt;ErrorList&gt;
  SECOND ATTEMPT
  </code></pre>
  <p>Entrez, unfortunately, does not have a man page or <code>--help</code> entry on my installation for some reason and I am not quite sure where I should change the one-liner to change this behavior.</p>
  <p>Does anyone have any clues?</p>
  
Tags: <database><entrez><efetch><ncbi>
Title: How to set Entrez Direct - ESearch NCBI entrez to pipe or ignore errors?
ThreadText: # How to set Entrez Direct - ESearch NCBI entrez to pipe or ignore errors?
  
  (Asked by: username_0 on 2023-01-27)
  
  I am using the following one-liner with `NCBI entrez` to query their databases from the terminal (see [Entrez Direct: E-utilities on the Unix Command Line](https://www.ncbi.nlm.nih.gov/books/NBK179288/):
  
  ```
  esearch -db assembly -query ${species name} |
      xtract -pattern ENTREZ_DIRECT -element Count
  
  ```
  
  This works a charm but occasionally it sends an xml error that messes up the output.
  
  Here is an example of the error:
  
  ```
  xml
  FAILURE ( Fri Jan 27 01:12:44 PM CST 2023 )
  nquire -url https://eutils.ncbi.nlm.nih.gov/entrez/eutils/ esearch.fcgi -retmax 0 -usehistory y -db assembly -term "Crepis commutata" -tool edirect -edirect 18.7 -edirect_os Linux -email {}
  <ErrorList>
    <PhraseNotFound>commutata</PhraseNotFound>
    <PhraseNotFound>Crepis commutata[All Fields]</PhraseNotFound>
  <ErrorList>
  SECOND ATTEMPT
  
  ```
  
  Entrez, unfortunately, does not have a man page or `--help` entry on my installation for some reason and I am not quite sure where I should change the one-liner to change this behavior.
  
  Does anyone have any clues?
  
  **Tags:** database, entrez, efetch, ncbi
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2023-01-27. Score: 1 | Accepted answer
  
  This is because there are not assemblies for *Crepis commutate* within NCBI's assembly database.
  
  The cross check is here:
  
  [https://www.ncbi.nlm.nih.gov/assembly/?term=Crepis+commutata](https://www.ncbi.nlm.nih.gov/assembly/?term=Crepis%20commutata)
  
  The output is a bit clearer than Entrez
  
  > The following terms were not found in Assembly: commutata, Crepis commutata[All Fields].
  > No items found.
  
  All you need do to correct it is issue a `next` statement in the a loop of species above the code you've presented.
  
  ```
  if [[ "$species" == 'Crepis commutata' ]]; then
    continue
  fi
  esearch -db assembly -query "$species" | xtract -pattern ENTREZ_DIRECT -element Count
  
  ```
  
  ---
  
  To answer the comments if this is done via a Python subprocess, you could simply issue the following code (which has not been checked)
  
  ```
  import subprocess
  
  for species in List:
      try:
          subprocess.run(["esearch", "-db" "assembly", "-query", f"${species}", "|", "xtract", "-pattern", "ENTREZ_DIRECT", "-", "element"], shell=True")
      except ValueError as ve:
          print(f'Species {species}, is not present.')
          continue
  
  ```
  
  > **Comments:**
  > **username_0**: Right but is there a way to set `entrez` tools to pipe the error? Being able to do that would help me clean up the output produced from an automated session a bit easier. **Crepis commutate** no existing on NCBI is not the issue, rather not being able to cleanly pipe the outcome is the issue.  
  > **username_2**: 2>&1      Merge stderr into stdout ; https://stackoverflow.com/questions/818255/what-does-21-mean  
  
  ---
  
  