def run_cli(self, pig, verbose=True):
with TemporaryDirectory(prefix='<STR_LIT>') as tmp_dir:<EOL><INDENT>with NamedTemporaryFile(dir=tmp_dir) as f:<EOL><INDENT>f.write(pig.encode('<STR_LIT:utf-8>'))<EOL>f.flush()<EOL>fname = f.name<EOL>pig_bin = '<STR_LIT>'<EOL>cmd_extra = []<EOL>pig_cmd = [pig_bin, '<STR_LIT>', fname] + cmd_extra<EOL>if self.pig_properties:<EOL><INDENT>pig_properties_list = self.pig_properties.split()<EOL>pig_cmd.extend(pig_properties_list)<EOL><DEDENT>if verbose:<EOL><INDENT>self.log.info("<STR_LIT:%s>", "<STR_LIT:U+0020>".join(pig_cmd))<EOL><DEDENT>sp = subprocess.Popen(<EOL>pig_cmd,<EOL>stdout=subprocess.PIPE,<EOL>stderr=subprocess.STDOUT,<EOL>cwd=tmp_dir,<EOL>close_fds=True)<EOL>self.sp = sp<EOL>stdout = '<STR_LIT>'<EOL>for line in iter(sp.stdout.readline, b'<STR_LIT>'):<EOL><INDENT>stdout += line.decode('<STR_LIT:utf-8>')<EOL>if verbose:<EOL><INDENT>self.log.info(line.strip())<EOL><DEDENT><DEDENT>sp.wait()<EOL>if sp.returncode:<EOL><INDENT>raise AirflowException(stdout)<EOL><DEDENT>return stdout<EOL><DEDENT><DEDENT>
Run an pig script using the pig cli

>>> ph = PigCliHook()
>>> result = ph.run_cli("ls /;")
>>> ("hdfs://" in result)
True