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, sys
24
25async def run_client():
26    async with asyncssh.connect('localhost') as conn:
27        proc1 = await conn.create_process(r'echo "1\n2\n3"')
28        proc2_result = await conn.run('tail -r', stdin=proc1.stdout)
29        print(proc2_result.stdout, end='')
30
31try:
32    asyncio.get_event_loop().run_until_complete(run_client())
33except (OSError, asyncssh.Error) as exc:
34    sys.exit('SSH connection failed: ' + str(exc))
35