Icon

kn_​example_​python_​bash_​node

carstenhaubold suggests a replacement for the NGS tools Bash node using the bundled Python in KNIME

carstenhaubold suggests a replacement for the NGS tools Bash node using the bundled Python in KNIME

import knime.scripting.io as knioimport subprocess as spimport pandas as pd# https://forum.knime.com/t/external-tool-issues-and-high-difficulty-to-use/58252/12?u=mlauber71# equivalent to the input fields of the NGS bash node:cmd = 'ls -lah'working_dir = knio.flow_variables['context.workflow.absolute-path']proc = sp.run(cmd.split(""), cwd=working_dir, capture_output=True)def get_lines_not_empty(stream): lines = stream.decode().splitlines() if len(lines) == 0: return [""] # because KNIME doesn't like a completely empty data frame else: return linesdf_stdout = pd.DataFrame({"StdOut": get_lines_not_empty(proc.stdout)})df_stderr = pd.DataFrame({"StdErr": get_lines_not_empty(proc.stderr)})knio.output_tables[0] = knio.Table.from_pandas(df_stdout)knio.output_tables[1] = knio.Table.from_pandas(df_stderr) carstenhaubold suggests a replacement for the NGS tools Bash node using the bundled Python in KNIME extract the context Python Script Extract ContextProperties import knime.scripting.io as knioimport subprocess as spimport pandas as pd# https://forum.knime.com/t/external-tool-issues-and-high-difficulty-to-use/58252/12?u=mlauber71# equivalent to the input fields of the NGS bash node:cmd = 'ls -lah'working_dir = knio.flow_variables['context.workflow.absolute-path']proc = sp.run(cmd.split(""), cwd=working_dir, capture_output=True)def get_lines_not_empty(stream): lines = stream.decode().splitlines() if len(lines) == 0: return [""] # because KNIME doesn't like a completely empty data frame else: return linesdf_stdout = pd.DataFrame({"StdOut": get_lines_not_empty(proc.stdout)})df_stderr = pd.DataFrame({"StdErr": get_lines_not_empty(proc.stderr)})knio.output_tables[0] = knio.Table.from_pandas(df_stdout)knio.output_tables[1] = knio.Table.from_pandas(df_stderr) carstenhaubold suggests a replacement for the NGS tools Bash node using the bundled Python in KNIME extract the contextPython Script Extract ContextProperties

Nodes

Extensions

Links