Python Os System Sh Syntax Error Redirection Unexpected
Contents |
Get Kubuntu Get Xubuntu Get Lubuntu Get UbuntuStudio Get Mythbuntu Get Edubuntu Get Ubuntu-GNOME Get UbuntuKylin Ubuntu Code of Conduct Ubuntu Wiki Community Wiki Other Support Launchpad Answers syntax error redirection unexpected ubuntu Ubuntu IRC Support AskUbuntu Official Documentation User Documentation Social Media Facebook Twitter Useful
Cron Redirection Unexpected
Links Distrowatch Bugs: Ubuntu PPAs: Ubuntu Web Upd8: Ubuntu OMG! Ubuntu Ubuntu Insights Planet Ubuntu Activity Page Please read before
!#/bin/bash: Not Found
SSO login Advanced Search Forum The Ubuntu Forum Community Ubuntu Official Flavours Support General Help [SOLVED] Misbehaving python os.system() call Having an Issue With Posting ? Do you want to help us debug
Bash Redirection
the posting issues ? < is the place to report it, thanks ! Results 1 to 4 of 4 Thread: Misbehaving python os.system() call Thread Tools Show Printable Version Subscribe to this Thread… Display Linear Mode Switch to Hybrid Mode Switch to Threaded Mode December 8th, 2009 #1 Quantum7 View Profile View Forum Posts Private Message First Cup of Ubuntu Join Date Oct 2009 Beans debconf-set-selections 4 Misbehaving python os.system() call I am noticing a couple bizarre results to os.system() calls. Could somebody confirm similar output? I'm using 9.10 with python 2.6.4 Code: $ python -c 'import os; os.system("time echo hi")' hi 0.00user 0.00system 0:00.00elapsed 0%CPU (0avgtext+0avgdata 0maxresident)k 0inputs+0outputs (0major+215minor)pagefaults 0swaps $ time echo hi hi real 0m0.000s user 0m0.000s sys 0m0.000s or Code: $ python -c 'import os; os.system("bash<<<\"echo hi\"")' sh: Syntax error: redirection unexpected $ bash<<<"echo hi" hi These both work fine under CentOS and OS X with the same python versions. If anyone cares to suggest a workaround, I'm actually interested in running scripts like Code: $ ( time command >output 2>errors ; ) 2> timing Adv Reply December 8th, 2009 #2 Brandon Williams View Profile View Forum Posts Fresh Brewed Ubuntu Join Date Jan 2009 BeansHidden! Re: Misbehaving python os.system() call The problem is suggested by the output from python. Originally Posted by Quantum7 Code: $ python -c 'import os; os.system("bash<<<\"echo hi\"")' sh: Syntax error: redirection unexpected When it runs the os.system method, it uses sh as the shell, which is dash in Ubuntu. It's quite likely to be bash in other versions of Linux.
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow syntax error: "(" unexpected the company Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 6.2 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up Error when using os.system in python but not in shell up vote 1 down vote favorite I am https://ubuntuforums.org/showthread.php?t=1349347 trying to redirect the out of gnu make. Want to redirect ALL to both STDOUT and all.log and error only to error.log. Below is my program #!/usr/bin/env python import optparse import os import sys import commands command = 'make all > >(tee -a all.log ) 2>&1 2> >(tee -a error.log )' SysReturnVal=os.system(command) print "system return value is ", SysReturnVal When I execute it getting sh: -c: line 0: syntax error near unexpected http://stackoverflow.com/questions/37785106/error-when-using-os-system-in-python-but-not-in-shell token `>' sh: -c: line 0: `make all > >(tee -a all.log ) 2>&1 2> >(tee -a error.log )' But executing the same command on linux bash shell executes without error. make all > >(tee -a all.log ) 2>&1 2> >(tee -a error.log ) Why is this failing when running in python script using os.system, but not in terminal/bash shell ? python linux bash shell share|improve this question asked Jun 13 at 8:34 Manjunath C M 91 Which shell are you using? It looks like you're trying to do some none-portable things that work in your shell but not with sh. –Biffen Jun 13 at 8:40 sh points to bash in centos 6.4. I tried the same command on bash and it works fine and in python the same command with os.system fails with sh errors. –Manjunath C M Jun 13 at 8:45 1 When you run Bash via a symlink called sh, Bash will run in sh compatibility mode, and won't let you use any Bashisms. You can try running /bin/sh interactively and see the difference. –Biffen Jun 13 at 8:46 add a comment| 2 Answers 2 active oldest votes up vote 0 down vote os.system() calls *nix system() call. The system() library function uses fork(2) to cr
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us http://stackoverflow.com/questions/2462317/bash-syntax-error-redirection-unexpected Learn more about Stack Overflow the company Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 6.2 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up Bash: Syntax error: redirection unexpected up vote 54 syntax error down vote favorite 11 I do this in a script: read direc <<< $(basename `pwd`) and I get: Syntax error: redirection unexpected in an ubuntu machine /bin/bash --version GNU bash, version 4.0.33(1)-release (x86_64-pc-linux-gnu) while I do not get this error in another suse machine: /bin/bash --version GNU bash, version 3.2.39(1)-release (x86_64-suse-linux-gnu) Copyright (C) 2007 Free Software Foundation, Inc. Why the error? bash share|improve this question edited Mar syntax error redirection 6 at 17:20 Willi Mentzel 2,34591840 asked Mar 17 '10 at 12:58 flow 4,3133295157 For reference, the command works on cygwin as well ( /bin/bash --version GNU bash, version 3.2.49(23)-release (i686-pc-cygwin) Copyright (C) 2007 Free Software Foundation, Inc. ) –hlovdal Mar 17 '10 at 13:08 add a comment| 3 Answers 3 active oldest votes up vote 94 down vote accepted Does your script reference /bin/bash or /bin/sh in its hash bang line? The default system shell in Ubuntu is dash, not bash, so if you have #!/bin/sh then your script will be using a different shell than you expect. Dash does not have the <<< redirection operator. share|improve this answer answered Mar 17 '10 at 13:05 John Kugelman 174k36306384 Is there a way to fix this easily ? –Sliq Dec 21 '14 at 20:52 3 @Sliq, yes use !#/bin/bash. –ahmet alp balkan Jan 4 '15 at 21:03 2 seems this is happenning to me in a shell script with a <<< operator thas works on my local machine but not on the server; but using !#/bin/bash does not solve the problem. Local is "3.2.0-74-generic #109-Ubuntu", server is "3.5.0-54-generic #81~precise1-Ubuntu" –Packet Tracer Jan