Run Sqoop with python 3 using subprocess
<p>I am trying to run Sqoop command with python</p>

<pre><code>subprocess.call(["sqoop","import","--connect", "jdbc:oracle:thin:@hostname:1521/ARSMTREP","--username", "username" ,"--password", "password","--table","ARADMIN."+line,"--as-textfile","--target-dir","/data/"+line])
</code></pre>

<p>able to execute this code but when I am trying to execute with "--fields-terminated-by"+" "+"'~'" it's giving tool import error</p>

<pre><code>process=subprocess.call(["sqoop","import","--connect", "jdbc:oracle:thin:@hostname:1521/ARSMTREP","--username", "hadoop_user" ,"--password", "password","--table","ARADMIN."+line,"--fields-terminated-by"+" "+"'~'","--as-textfile","--target-dir","/data/"+line])
</code></pre>

<blockquote>
  <p>Error parsing arguments for import</p>
</blockquote>

<pre><code>process=subprocess.call(["sqoop","import","--connect", "jdbc:oracle:thin:@hostname:1521/ARSMTREP","--username", "hadoop_user" ,"--password", "password","--table","ARADMIN."+line,"--fields-terminated-by","~","--as-textfile","--target-dir","/data/"+line])
</code></pre>

<p>This code call the sqoop command and executes them from linux terminal . Subprocess call <a href="https://docs.python.org/3/library/subprocess.html" rel="nofollow">Python subprocess</a> you can also use <code>os.system()</code> to execute the Sqoop query from python . But its preferable the call Subprocess .
There is no white space in arguments inside the <code>subprocess.call()</code> or else it will provide the error. </p>

<p>In above code all the argument are Sqoop command only the <code>line</code>is variable which takesthe table name from list.</p>

python python-3.x sqoop apache-sqoop