LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 09-25-2016, 12:28 PM   #1
mrthingfish
LQ Newbie
 
Registered: Sep 2016
Posts: 1

Rep: Reputation: Disabled
Perl to Python


I've got a bit of perl code that I've been asked to translate to python. For the most part it's not been too challenging, but I'm stuck on this last bit:

Code:
my $bashcode=<<'__bash__';
. /opt/qip/etc/qiprc;
. /opt/sybase/sybase.sh
perl -mdata::dumper -e 'print dumper \%ENV';
__bash__
my $var1;
eval qx(bash -c "$bashcode");
So, I'm pretty sure this is setting up an environment in which to run a new bash and later backtick some calls to a sybase db (?) like:

Code:
`qip-search -n $new_shortname -u qipman -p qipman`
Any advice on how to do all this in python?

Thanks in advance
 
Old 09-25-2016, 01:29 PM   #2
dugan
LQ Guru
 
Registered: Nov 2003
Location: Canada
Distribution: distro hopper
Posts: 11,235

Rep: Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320
Use subprocess.check_output if you want to run a command and capture its output.

https://docs.python.org/2/library/subprocess.html
 
Old 09-27-2016, 04:35 AM   #3
bigearsbilly
Senior Member
 
Registered: Mar 2004
Location: england
Distribution: Mint, Armbian, NetBSD, Puppy, Raspbian
Posts: 3,515

Rep: Reputation: 239Reputation: 239Reputation: 239
dear oh dear what is that?


Data:: Dumper not data::dumper just dumps a variable so you can see it.
%ENV is just the environment of the current process.

It looks all wrong:

try this on the command line:

perl -MData:: Dumper -e 'print Dumper(\%ENV)'


Note: spaces between :: and D as it turns into a stupid smiley

Last edited by bigearsbilly; 09-27-2016 at 04:38 AM.
 
Old 11-04-2016, 09:36 AM   #4
PurePenguin
LQ Newbie
 
Registered: Nov 2016
Posts: 10

Rep: Reputation: 0
Maybe this will be helpful --link removed by moderator--

Last edited by astrogeek; 11-04-2016 at 02:26 PM.
 
Old 11-04-2016, 02:25 PM   #5
astrogeek
Moderator
 
Registered: Oct 2008
Distribution: Slackware [64]-X.{0|1|2|37|-current} ::12<=X<=15, FreeBSD_12{.0|.1}
Posts: 6,269
Blog Entries: 24

Rep: Reputation: 4196Reputation: 4196Reputation: 4196Reputation: 4196Reputation: 4196Reputation: 4196Reputation: 4196Reputation: 4196Reputation: 4196Reputation: 4196Reputation: 4196
Quote:
Originally Posted by PurePenguin View Post
Maybe this will be helpful ...
Please note that advertising of third party services is not allowed in the forums.
Please contact ads@linuxquestions.org if you are interested in advertising on LQ.

Please also review the LQ Rules and Site FAQ to guide acceptable use of the forums.

Thanks.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Python related: How to access a Perl script behind a firewall from Python? vxc69 Programming 8 12-14-2010 07:32 AM
My needs: Perl vs. Python dave201 Programming 25 08-11-2007 11:13 PM
Python or Perl drdroid Programming 29 12-22-2006 09:54 AM
Perl or Python JJX Programming 6 10-27-2004 03:58 AM
Perl or Python ! linuxlover1 Programming 13 04-19-2004 07:33 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 04:04 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration