heredoc

Python subprocess with heredocs

女生的网名这么多〃 提交于 2019-12-05 12:41:40
I was playing around with Python's subprocess module, trying a few examples but I can't seem to get heredoc statements to work. Here is the trivial example I was playing with: import subprocess a = "A String of Text" p = subprocess.Popen(["cat", "<<DATA\n" + a + "\nDATA"]) I get the following error when I run the code above: cat: <<DATA\nA String of Text\nDATA: No such file or directory Am I doing it wrong? Is this even possible? If so how would I go about doing it? Update Just wanted to say that this should never be performed in a real python program because there are better ways of doing

ruby here documents

a 夏天 提交于 2019-12-05 05:35:33
问题 I am trying to write a method in Ruby that uses a here-document of HTML code with input variables and fills them in accordingly. My method is: calcForm(left, op, right, result) The html tags I am using are <input type="text" name="left" value="?????"> <select name="op"> <option value="add" ?????>+</option> <option value="mul" ?????>*</option> </select> <input type="text" name="right" value="?????"> = ????? Everywhere there are question marks my method has to fill in with variables left, op,

What's the difference between these two Perl snippets?

跟風遠走 提交于 2019-12-05 05:28:21
print <<EOF stuff EOF ; print <<EOF; stuff EOF Why would you use one over the other? Those two examples amount to the same thing behaviourally, but consider if you wanted to do something else after printing that block: print <<EOF stuff EOF . "more text here"; ...or maybe you need to test the result of the operation: print $unstable_filehandle <<EOF stuff EOF or warn "That filehandle finally disappeared: $!"; These examples are contrived, but you can see how sometimes it can be useful to be flexible about what code comes after the block of text. As tchrist points out, one thing that most

How to insert an inline (heredoc maybe? ) python script into a bash stdin/stdout streaming pipeline

杀马特。学长 韩版系。学妹 提交于 2019-12-04 14:18:06
I have recently been doing fair amount of work in python and would like to be able to use its features instead of shell/bash builtins / shell scripting. So for a shell pipeline like this: echo -e "Line One\nLine Two\nLine Three" | (cat<<-HERE | python import sys print 'stdout hi' for line in sys.stdin.readlines(): print ('stdout hi on line: %s\n' %line) HERE ) | tee -a tee.out All that is printed is "stdout hi" What needs to be fixed here? thanks! TrueY It would be better if you explained what your goal is with this construction. Maybe it could be simplified? The problem is with this script

PHP Heredoc String Rules

陌路散爱 提交于 2019-12-04 09:19:46
Can someone here explore the intricacies of using heredoc in PHP using example php code snippets? , based on what the manual says below? php.net manual says: It is very important to note that the line with the closing identifier must contain no other characters, except possibly a semicolon ( ; ). That means especially that the identifier may not be indented, and there may not be any spaces or tabs before or after the semicolon. It's also important to realize that the first character before the closing identifier must be a newline as defined by the local operating system. This is \n on UNIX

How to pipe a here-document through a command and capture the result into a variable?

不问归期 提交于 2019-12-04 08:24:35
问题 Right now this outputs the value I need on stdout. How can I capture it into a variable so I can use it in the rest of the script? Requirements: The script needs to be all in one file. I'd prefer not to write any temp files, if possible. . #!/bin/bash cat << EOF | xsltproc - ../pom.xml | tail -1 <?xml version="1.0"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:template match="/"><xsl:value-of select="/project/version"/></xsl:template> </xsl:stylesheet>

Can't find string terminator “str” anywhere before EOF

喜你入骨 提交于 2019-12-04 03:08:51
问题 Why I get this error? use strict; use warnings; my $str = <<str; 88087 23/11/2010 35192 25/07/2010 B3J 5X9 17/08/2011 C8U 5L6 16/08/2011 F4Q 3B4 17/10/2010 D3X 9P4 11/05/2010 O7L 6Z8 28/02/2010 W8L 9P2 05/09/2010 str print $str; my @arr = split/\n/,$str; foreach (@arr) { my @tmp = split/\t/; print "$tmp[1]\n"; } 回答1: You should not have a space here: str ^ The heredoc terminator should be on a line by itself and should not have anything (not even space ) surrounding it. 回答2: You can use

Is nesting of Here Document possible in a unix bash script?

社会主义新天地 提交于 2019-12-04 00:26:00
Is it possible to write a heredoc within another heredoc ? ssh -T -q yxz@server1 <<-"END_TEXT" . . ssh -T -q abc@server2 <<-"SUB_TEXT" . . SUB_TEXT . . END_TEXT Yes However, the nested heredoc terminator will only be recognized when indented if the indentation is done with actual tabs. Spaces won't work. So you probably want to do something more like: ssh s1 << \eof1 ssh s2 << \eof2 hostname eof2 eof1 来源: https://stackoverflow.com/questions/13254077/is-nesting-of-here-document-possible-in-a-unix-bash-script

ruby here documents

情到浓时终转凉″ 提交于 2019-12-03 22:15:35
I am trying to write a method in Ruby that uses a here-document of HTML code with input variables and fills them in accordingly. My method is: calcForm(left, op, right, result) The html tags I am using are <input type="text" name="left" value="?????"> <select name="op"> <option value="add" ?????>+</option> <option value="mul" ?????>*</option> </select> <input type="text" name="right" value="?????"> = ????? Everywhere there are question marks my method has to fill in with variables left, op, right, and result. For example, calcForm(6, "mul", 7, 42) should return the string: <input type="text"

Can I access a variable within a heredoc in Ruby?

三世轮回 提交于 2019-12-03 22:06:19
If I have a method def some_method p = {} string = <<-MY_TERMINATOR Example text blah blah lorem ipsum something or another MY_TERMINATOR end how can I access the variable p[:name] from within the heredoc? You can interpolate just like in normal strings <<-TERMINATOR Example #{p[:name]} blah blah blah TERMINATOR 来源: https://stackoverflow.com/questions/3332849/can-i-access-a-variable-within-a-heredoc-in-ruby