1#!/usr/bin/env python3.6 2# 3# Copyright (c) 2013-2018 by Ron Frederick <ronf@timeheart.net> and others. 4# 5# This program and the accompanying materials are made available under 6# the terms of the Eclipse Public License v2.0 which accompanies this 7# distribution and is available at: 8# 9# http://www.eclipse.org/legal/epl-2.0/ 10# 11# This program may also be made available under the following secondary 12# licenses when the conditions for such availability set forth in the 13# Eclipse Public License v2.0 are satisfied: 14# 15# GNU General Public License, Version 2.0, or any later versions of 16# that license 17# 18# SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later 19# 20# Contributors: 21# Ron Frederick - initial implementation, API, and documentation 22 23import asyncio, asyncssh, subprocess, sys 24 25async def run_client(): 26 async with asyncssh.connect('localhost') as conn: 27 local_proc = subprocess.Popen(r'echo "1\n2\n3"', shell=True, 28 stdout=subprocess.PIPE) 29 remote_result = await conn.run('tail -r', stdin=local_proc.stdout) 30 print(remote_result.stdout, end='') 31 32try: 33 asyncio.get_event_loop().run_until_complete(run_client()) 34except (OSError, asyncssh.Error) as exc: 35 sys.exit('SSH connection failed: ' + str(exc)) 36