CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
Outputting from a terminal invocation

 



CR15P0
New User

Oct 15, 2012, 5:40 AM

Post #1 of 5 (1191 views)
Outputting from a terminal invocation Can't Post

Hi, I use a workflow product called Enfocus Switch and this allows me to execute commands that allow me to run perl directly within the application. This is great because I can get perl to do complex alterations to documents that are running through the workflow. However Switch does not like to use of the greater than symbol ">" so this:

perl -e "print 'hello world'" > "/Users/user/test_out.txt"

cannot be used. Do you know of a way of replacing the > so that I can still output a file? (BTW I have tried invoking tee: perl -e "print 'hello world'" | tee "/Users/richardcrisp/test_out.txt" but Switch doesn't like "|" either!). Many other applications (cpdf, qrencode, etc) do not use > but instead use -o. I know that this command is used for something else in perl but was hoping there'd be something similar.

Thanks for you help!


(This post was edited by CR15P0 on Oct 15, 2012, 10:30 AM)


Laurent_R
Veteran / Moderator

Oct 15, 2012, 10:42 AM

Post #2 of 5 (1184 views)
Re: [CR15P0] Outputting from a terminal invocation [In reply to] Can't Post

You could possibly pass the file name as a parameter to the script and then open manually the output file in your Perl code.


rovf
Veteran

Oct 17, 2012, 7:12 AM

Post #3 of 5 (1179 views)
Re: [CR15P0] Outputting from a terminal invocation [In reply to] Can't Post

I guess Switch does not load a shell to run the commands. How about providing a shell explicitly? For example to use zsh (feel free to use any other shell you like), what happens if you try out this:


Code
zsh -f -c "perl -le 'print 4711' > test_out.txt"



CR15P0
New User

Oct 17, 2012, 10:05 AM

Post #4 of 5 (1170 views)
Re: [rovf] Outputting from a terminal invocation [In reply to] Can't Post

You my friend are a legend!!

Your example worked fantastically and I was ecstatic, however, although this has worked in your example for some reason when I try:

sh -f -c "perl -lpe 's/L/l/g' test.txt > test_out.txt"
or
sh -f -c "perl -p -le 's/L/l/g' test.txt > test_out.txt"

I get nothing (although the perl lines work fine in the terminal directly). I'm guessing it has something to do with the need to add the "-p" in there but without that I get a blank output (in perl). I've also tried replacing the single quotes with double quotes but still nothing, not even a blank document where it's tried to make a file.

p.s. I also tried complete file paths /Users/username/text*.txt


(This post was edited by CR15P0 on Oct 17, 2012, 10:19 AM)


rovf
Veteran

Oct 18, 2012, 6:36 AM

Post #5 of 5 (1162 views)
Re: [CR15P0] Outputting from a terminal invocation [In reply to] Can't Post

I don't know about the framework you are using, in particular, whether it does something to the commands before executing them. I would put your command into a shell script, and invoke the script instead. This would also help with debugging.

Also, it might make sense to collect stderr in a file for later inspection.

BTW - since I don't know your general context -, are you sure that you really want the redirection to be >test_out.txt, and not >>test_out.txt ?

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives