pipe

How to redirect input in Powershell without BOM?

烈酒焚心 提交于 2020-02-22 04:18:05
问题 I am trying to redirect input in Powershell by Get-Content input.txt | my-program args The problem is the piped UTF-8 text is preceded with a BOM (0xefbbbf), and my program cannot handle that correctly. A minimal working example: // File: Hex.java import java.io.IOException; public class Hex { public static void main(String[] dummy) { int ch; try { while ((ch = System.in.read()) != -1) { System.out.print(String.format("%02X ", ch)); } } catch (IOException e) { } } } Then in powershell javac

File not found error when launching a subprocess containing piped commands

会有一股神秘感。 提交于 2020-02-12 08:25:01
问题 I need to run the command date | grep -o -w '"+tz+"'' | wc -w using Python on my localhost. I am using subprocess module for the same and using the check_output method as I need to capture the output for the same. However it is throwing me an error : Traceback (most recent call last): File "test.py", line 47, in <module> check_timezone() File "test.py", line 40, in check_timezone count = subprocess.check_output(command) File "/usr/lib/python2.7/subprocess.py", line 537, in check_output

File not found error when launching a subprocess containing piped commands

此生再无相见时 提交于 2020-02-12 08:24:30
问题 I need to run the command date | grep -o -w '"+tz+"'' | wc -w using Python on my localhost. I am using subprocess module for the same and using the check_output method as I need to capture the output for the same. However it is throwing me an error : Traceback (most recent call last): File "test.py", line 47, in <module> check_timezone() File "test.py", line 40, in check_timezone count = subprocess.check_output(command) File "/usr/lib/python2.7/subprocess.py", line 537, in check_output

redis里的“流水线”pipeline/pool

情到浓时终转凉″ 提交于 2020-02-08 04:38:33
pipeline 流水线 定义:批量执行redis命令,减少通信io,提高执行效率 注意:此为客户端技术,而不是服务端技术 示例 import redis # 创建连接池并连接到redis pool = redis . ConnectionPool ( host = '127.0.0.1' , db = 0 , port = 6379 ) r = redis . Redis ( connection_pool = pool ) pipe = r . pipeline ( ) pipe . set ( 'fans' , 50 ) pipe . incr ( 'fans' ) pipe . incrby ( 'fans' , 100 ) pipe . execute ( ) 性能对比 # 创建连接池并连接到redis pool = redis . ConnectionPool ( host = '127.0.0.1' , db = 0 , port = 6379 ) r = redis . Redis ( connection_pool = pool ) def withpipeline ( r ) : p = r . pipeline ( ) for i in range ( 1000 ) : key = 'test1' + str ( i ) value = i + 1 p .

NIO管道Pipe

不打扰是莪最后的温柔 提交于 2020-02-05 05:12:34
实现开启一条线程向Pipe 管道里面写入数据,另一条线程读取Pipe管道里面的数据 package com . mock ; import org . junit . jupiter . api . Test ; import java . io . IOException ; import java . nio . ByteBuffer ; import java . nio . channels . Pipe ; import java . time . LocalTime ; public class TestPipe { @Test public void test ( ) throws Exception { final Pipe pipe = Pipe . open ( ) ; //一条线程向管道写数据,另一条线程从管道中读取数据 new Thread ( ( ) - > write ( pipe ) ) . start ( ) ; new Thread ( ( ) - > read ( pipe ) ) . start ( ) ; Thread . sleep ( 6000 ) ; } //写数据到管道 public void write ( Pipe pipe ) { try { ByteBuffer byteBuffer = ByteBuffer .

IPC通信_无名管道(PIPE)

十年热恋 提交于 2020-02-02 23:56:30
无名管道只能在具有公共祖先的两个进程间使用,且建议半双工使用 ( 因为历史上就是半双工,虽然有些系统支持全双工管道 ) 。 无名管道通过 pipe 函数创建 #include <unistd.h> int pipe(int fd[2]); 其中:参数 fd 返回两个文件描述符, fd[0] 只用来读,是输出 ,fd[1] 只用来写,是输入。 举例: #include <fcntl.h> #include <unistd.h> #include <stdio.h> #include <stdlib.h> // linux支持双通道? int main() { int fd[2]; int pid = 0; int n = 0; char buf[128] = {0}; if(pipe(fd) < 0) { printf("pipe failed\n"); return -1; } if(pid = fork() == 0) {// 子进程 printf("child print\n"); close(fd[0]); write(fd[1],"hello,this is child\n",40); } else {// 父进程 printf("father print\n"); close(fd[1]); n = read(fd[0],buf,sizeof(buf)); if(n >

Different behaviour and output when piping through CMD and PowerShell

不羁的心 提交于 2020-02-02 13:16:43
问题 I am trying to pipe the content of a file to a simple ASCII symmetrical encryption program i made. It's a simple program that reads input from STDIN and adds or subtracts a certain value (224) to each byte of the input. For example: if the first byte is 4 and we want to encrypt, then it becomes 228. If it exceeds 255, the program just performs some modulo. This is the output I get with cmd (test.txt contains "this is a test"): type .\test.txt | .\Crypt.exe --encrypt | .\Crypt.exe --decrypt

gulp教程之gulp-uglify

馋奶兔 提交于 2020-02-02 05:46:32
简介: 使用gulp-uglify压缩javascript文件,减小文件大小。 1、安装nodejs/全局安装gulp/项目安装gulp/创建package.json和gulpfile.js文件 1.1、gulp基本使用还未掌握?请参看: gulp详细入门教程 1.2、本示例目录结构如下: 2、本地安装gulp-uglify 2.1、github: https://github.com/terinjokes/gulp-uglify 2.2、安装:命令提示符执行 cnpm install gulp-uglify --save-dev 2.3、注意:没有安装 cnpm 请使用 npm install gulp-uglify --save-dev 。 什么是cnpm,如何安装? 2.4、说明: --save-dev 保存配置信息至 package.json 的 devDependencies 节点。 为什么要保存至package.json? 3、配置gulpfile.js 3.1、基本使用 JavaScript 1 2 3 4 5 6 7 8 var gulp = require ( 'gulp' ) , uglify = require ( 'gulp-uglify' ) ; gulp . task ( 'jsmin' , function ( ) { gulp . src (

前端构建工具gulp入门教程

孤街浪徒 提交于 2020-02-02 05:44:20
新建Gulpfile文件,运行gulp 安装好gulp后我们需要告诉它要为我们执行哪些任务,首先,我们自己需要弄清楚项目需要哪些任务。 检查Javascript 编译Sass(或Less之类的)文件 合并Javascript 压缩并重命名合并后的Javascript 安装依赖 npm install gulp-jshint gulp-sass gulp-concat gulp-uglify gulp-rename --save-dev 新建gulpfile文件 现在,组件都安装完毕,我们需要新建gulpfile文件以指定gulp需要为我们完成什么任务。 gulp只有五个方法: task , run , watch , src ,和 dest ,在项目根目录新建一个js文件并命名为 gulpfile.js ,把下面的代码粘贴进去: // 引入 gulp var gulp = require('gulp'); // 引入组件 var jshint = require('gulp-jshint'); var sass = require('gulp-sass'); var concat = require('gulp-concat'); var uglify = require('gulp-uglify'); var rename = require('gulp-rename');

gulp教程之gulp-less

ぃ、小莉子 提交于 2020-02-02 05:35:31
1、安装nodejs/全局安装gulp/项目安装gulp/创建package.json和gulpfile.js文件 1.1、gulp基本使用还未掌握?请参看: gulp详细入门教程 1.2、本示例目录结构如下: 2、本地安装gulp-less 2.1、github: https://github.com/plus3network/gulp-less 2.3、安装:命令提示符执行 cnpm install gulp-less --save-dev 2.4、注意:没有安装cnpm请使用 npm install gulp-less --save-dev 什么是cnpm,如何安装? 2.5、说明: --save-dev 保存配置信息至 package.json 的 devDependencies 节点。 为什么要保存至package.json? 3、配置gulpfile.js 3.1、基本使用 JavaScript 1 2 3 4 5 6 7 8 var gulp = require ( 'gulp' ) , less = require ( 'gulp-less' ) ; gulp . task ( 'testLess' , function ( ) { gulp . src ( 'src/less/index.less' ) . pipe ( less ( ) ) . pipe (