Help convert a line of cshell to python

This is the place for queries that don't fit in any of the other categories.

Help convert a line of cshell to python

Postby eedodge3 » Mon Jul 29, 2013 6:07 pm

This line works in cshell. How do i re-write this to work in Pyhon? Thanks in advance.

(/somegroup/bin/cmlist -scope time@ea@ps@type@oor@sp@pc@pt >! {$deflogdir}test.txt) >&! {$cmerr}
Last edited by Yoriz on Mon Jul 29, 2013 8:49 pm, edited 1 time in total.
Reason: changed title
eedodge3
 
Posts: 17
Joined: Mon Jul 29, 2013 5:59 pm

Re: Help running other command in Python

Postby Yoriz » Mon Jul 29, 2013 6:32 pm

I have no idea what that does, how much pthon do you know ?
New Users, Read This
Join the #python-forum IRC channel on irc.freenode.net!
Spam topic disapproval technician
Windows7, Python 2.7.4., WxPython 2.9.5.0., some Python 3.3
User avatar
Yoriz
 
Posts: 833
Joined: Fri Feb 08, 2013 1:35 am
Location: UK

Re: Help running other command in Python

Postby micseydel » Mon Jul 29, 2013 8:24 pm

I'm not sure that anyone here will know cshell, but if you can explain what you want, we can help you with that.
Join the #python-forum IRC channel on irc.freenode.net!

Please do not PM members regarding questions which are meant to be discussed publicly. The point of the forum is so that others can benefit from it. We don't want to help you over PMs or emails.
User avatar
micseydel
 
Posts: 1358
Joined: Tue Feb 12, 2013 2:18 am
Location: Mountain View, CA

Re: Help running other command in Python

Postby eedodge3 » Mon Jul 29, 2013 8:51 pm

thanks for all the replies. i have very little knowledge in pyhon.

the "/somegroup/bin/cmlist -scope time@ea@ps@type@oor@sp@pc@pt" is used to pull some data from some location. Then the output is saved to some file (>! {$deflogdir}test.txt). Any error is routed to a different file(>&! {$cmerr})

i need something in python to do something like
>>>execute ( "/somegroup/bin/cmlist -scope time@ea@ps@type@oor@sp@pc@pt") so i can pull the data.
eedodge3
 
Posts: 17
Joined: Mon Jul 29, 2013 5:59 pm

Re: Help convert a line of cshell to python

Postby Yoriz » Mon Jul 29, 2013 9:07 pm

Writing data to files is easy enough, but your discription is not very clear.
pull some data
What sort of data ? some text or some other?

from some location
what type of location? a file , a database ect

Any error is routed to a different file
What is it that causes errors ?

Is it just a simple matter of copy from one file to another or is it something entirly differant?
New Users, Read This
Join the #python-forum IRC channel on irc.freenode.net!
Spam topic disapproval technician
Windows7, Python 2.7.4., WxPython 2.9.5.0., some Python 3.3
User avatar
Yoriz
 
Posts: 833
Joined: Fri Feb 08, 2013 1:35 am
Location: UK

Re: Help convert a line of cshell to python

Postby eedodge3 » Mon Jul 29, 2013 9:45 pm

(/somegroup/bin/cmlist -scope time@ea@ps@type@oor@sp@pc@pt >! {$deflogdir}test.txt) >&! {$cmerr}

- the "cmlist" is a shell script located in folder /somegroup/bin/.
- the "-scope time@ea@ps@type@oor@sp@pc@pt" is just arguments on what content to pull
- the data to pull is text
- the data location is a database (i think)

the line in question is inside another shell script. i'm trying python to re-write the shell script that calls this other shell script. i just need to call it.
eedodge3
 
Posts: 17
Joined: Mon Jul 29, 2013 5:59 pm

Re: Help convert a line of cshell to python

Postby stranac » Tue Jul 30, 2013 5:06 am

You can use subprocess to do this:
Code: Select all
import subprocess

with open('path/to/output', 'w') as out_file, open('path/to/errors', 'w') as error_file:
    subprocess.call(['/somegroup/bin/cmlist', '-scope', 'that_arg'], stdout=out_file, stderr=error_file)


Can't test that right now, but I think I got it right.

If you actually want to work with the data from python, it's possible you'll want to do something other than writing output to files.
Just read the subprocess docs, and you should be able to do what you want.
Friendship is magic!

R.I.P. Tracy M. You will be missed.
User avatar
stranac
 
Posts: 1144
Joined: Thu Feb 07, 2013 3:42 pm

Re: Help convert a line of cshell to python

Postby eedodge3 » Tue Jul 30, 2013 4:38 pm

thanks stranac. it worked! i just needed to nest the 'with open' statement because i have 2.6 version.

Code: Select all
with open('path/to/output', 'w') as out_file:
            with open('path/to/errors', 'w') as error_file:
                        subprocess.call(['/somegroup/bin/cmlist', '-scope', 'that_arg'], stdout=out_file, stderr=error_file)


many thanks to you again and to all that replied to my post.

python is awesome!!!
Last edited by Yoriz on Tue Jul 30, 2013 4:42 pm, edited 1 time in total.
Reason: Added code tags
eedodge3
 
Posts: 17
Joined: Mon Jul 29, 2013 5:59 pm

Re: Help convert a line of cshell to python

Postby Yoriz » Tue Jul 30, 2013 4:45 pm

Code: Select all
with open('path/to/output', 'w') as out_file,\
        open('path/to/errors', 'w') as error_file:
    subprocess.call(['/somegroup/bin/cmlist', '-scope', 'that_arg'],
        stdout=out_file, stderr=error_file)
New Users, Read This
Join the #python-forum IRC channel on irc.freenode.net!
Spam topic disapproval technician
Windows7, Python 2.7.4., WxPython 2.9.5.0., some Python 3.3
User avatar
Yoriz
 
Posts: 833
Joined: Fri Feb 08, 2013 1:35 am
Location: UK

Re: Help convert a line of cshell to python

Postby eedodge3 » Tue Jul 30, 2013 4:59 pm

thanks yoriz.
eedodge3
 
Posts: 17
Joined: Mon Jul 29, 2013 5:59 pm


Return to General Coding Help

Who is online

Users browsing this forum: No registered users and 7 guests