FAQ
Hi,

I am trying to write a simple python script to manipulate files and call
other programs. I have a program installed (rocs) which I run using
cygwin on my XP (but is not in python). Can I run the pyhton script and
then call the other program in the same script?

For example:
Python Code # this line opens a file
Python Code # this line splits the file into 4 different files
rocs # this line calls the program 'rocs' to run on the newly formed files
Python Code # this line renames rocs output files and saves them in the
right place.

Otherwise, I would have to write two scripts (before and after 'rocs'),
and run the 3 scripts/programs separately.

I am relatively new to python and don't know a lot about cygwin. Please
remember that if you try to answer me :) Thanks!

Search Discussions

  • Norseman at May 6, 2009 at 5:47 pm

    Ben Keshet wrote:
    Hi,

    I am trying to write a simple python script to manipulate files and call
    other programs. I have a program installed (rocs) which I run using
    cygwin on my XP (but is not in python). Can I run the pyhton script and
    then call the other program in the same script?

    For example:
    Python Code # this line opens a file
    Python Code # this line splits the file into 4 different files
    rocs # this line calls the program 'rocs' to run on the newly formed files
    Python Code # this line renames rocs output files and saves them in the
    right place.

    Otherwise, I would have to write two scripts (before and after 'rocs'),
    and run the 3 scripts/programs separately.
    I am relatively new to python and don't know a lot about cygwin. Please
    remember that if you try to answer me :) Thanks!
    --
    http://mail.python.org/mailman/listinfo/python-list
    ==========================================
    If you don't like a lot of typing that obscures the process,
    take a look at the spawn family.


    processPython 2.5.2 (r252:60911, Mar 4 2008, 10:40:55)
    [GCC 3.3.6] on linux2
    Type "help", "copyright", "credits" or "license" for more information.
    import os
    AbWd = os.spawnlp( os.P_WAIT,"abiword","abiword","")
    The P_WAIT stops python until the program (abiword in this case)
    completes. The "" at the end are for tokens to be given to the program
    and yes - contrary to manual, the program MUST be there TWICE (complete
    with any path needed).

    for windows this works:
    (can't cut and paste from a dos box!###%*&!!!)

    Python 2.5.1 ... on win32
    import os
    result = os.spawnl( os.P_WAIT, "d:\\winmcad\\mcad","")
    Runs the program mcad. Returns to python when mcad exits.


    Today: 20090506
    Python ver as snippets show.
    OS is Linux Slackware 10.2
    OS is Windows XP Pro

    Steve
  • Tim Chase at May 6, 2009 at 5:54 pm

    for windows this works:
    (can't cut and paste from a dos box!###%*&!!!)
    Depending on how it was spawned, you can either right-click in
    the window and choose Mark/Paste (when marking, use <enter> to
    terminate the selection; and selections are blockwise rectangular
    rather than linewise or characterwise). Alternatively, if you
    click on the system menu (the icon in the title-bar with
    resize/minimize/maximize/close/help), there should be an Edit
    submenu with the same options within.

    A pain, but at least feasible.

    HTH,

    -tkc
  • Shawn Milochik at May 6, 2009 at 6:12 pm

    On Wed, May 6, 2009 at 1:54 PM, Tim Chase wrote:
    for windows this works:
    (can't cut and paste from a dos box!###%*&!!!)
    Depending on how it was spawned, you can either right-click in the window
    and choose Mark/Paste (when marking, use <enter> to terminate the selection;
    and selections are blockwise rectangular rather than linewise or
    characterwise). ?Alternatively, if you click on the system menu (the icon in
    the title-bar with resize/minimize/maximize/close/help), there should be an
    Edit submenu with the same options within.

    A pain, but at least feasible.
    <snip>

    I know I'm coming to the conversation late, but here's what I do*:

    1. Use Cygwin. (http://www.cygwin.com/)
    2. Use PuttyCYG (http://code.google.com/p/puttycyg/)

    That way, you can basically use PuTTY to shell into your Windows box.

    Note: If you are familiar with the Linux command line, you will be in
    love with this solution. If you're a Windows-only type, then be
    forewarned that doing this will require you to type Unix/Linux
    commands (for the most part) instead of DOS commands.

    *Disclaimer: I use a Mac and Linux. This is my workaround when forced
    to use Windows. Your environment preferences may vary.
  • Norseman at May 6, 2009 at 11:02 pm

    Shawn Milochik wrote:
    On Wed, May 6, 2009 at 1:54 PM, Tim Chase wrote:
    for windows this works:
    (can't cut and paste from a dos box!###%*&!!!)
    Depending on how it was spawned, you can either right-click in the window
    and choose Mark/Paste (when marking, use <enter> to terminate the selection;
    and selections are blockwise rectangular rather than linewise or
    characterwise). Alternatively, if you click on the system menu (the icon in
    the title-bar with resize/minimize/maximize/close/help), there should be an
    Edit submenu with the same options within.

    A pain, but at least feasible.
    <snip>

    I know I'm coming to the conversation late, but here's what I do*:

    1. Use Cygwin. (http://www.cygwin.com/)
    2. Use PuttyCYG (http://code.google.com/p/puttycyg/)

    That way, you can basically use PuTTY to shell into your Windows box.

    Note: If you are familiar with the Linux command line, you will be in
    love with this solution. If you're a Windows-only type, then be
    forewarned that doing this will require you to type Unix/Linux
    commands (for the most part) instead of DOS commands.

    *Disclaimer: I use a Mac and Linux. This is my workaround when forced
    to use Windows. Your environment preferences may vary.
    --
    http://mail.python.org/mailman/listinfo/python-list
    ===================================

    Nope and no thanks.

    I'm talking about a Dos Box on Win XP Pro
    For Tim - I get junk from somewhere else in the system.
    I recognize it from hours and many open/close boxes ago, but it's not
    what I 'swiped".

    For Shawn - why would I want to run synthesizers? Or any other ...
    (There is nothing wrong with Cygwin, just not on everybody's system.
    Didn't come with the package.)

    I write in Linux and test on other peoples Window$
    ^
    Thunderbird did not mark
    that as a miss spelling?!!! Three cheers for them!

    Objective - stick with out of the box to get way less install problems.



    Steve
  • Grant Edwards at May 6, 2009 at 6:39 pm

    On 2009-05-06, Shawn Milochik wrote:

    I know I'm coming to the conversation late, but here's what I do*:

    1. Use Cygwin. (http://www.cygwin.com/)
    2. Use PuttyCYG (http://code.google.com/p/puttycyg/)

    That way, you can basically use PuTTY to shell into your
    Windows box.
    Better yet, set up sshd in your Cygwin install, and then use
    whatever terminal you normally use on your Linux/MacOS box to
    ssh into the Cygwin box. When run that way, windows is almost
    usable...

    --
    Grant Edwards grante Yow! Oh, I get it!!
    at "The BEACH goes on", huh,
    visi.com SONNY??
  • Shawn Milochik at May 6, 2009 at 6:47 pm

    On Wed, May 6, 2009 at 2:39 PM, Grant Edwards wrote:
    On 2009-05-06, Shawn Milochik wrote:

    I know I'm coming to the conversation late, but here's what I do*:

    1. Use Cygwin. (http://www.cygwin.com/)
    2. Use PuttyCYG (http://code.google.com/p/puttycyg/)

    That way, you can basically use PuTTY to shell into your
    Windows box.
    Better yet, set up sshd in your Cygwin install, and then use
    whatever terminal you normally use on your Linux/MacOS box to
    ssh into the Cygwin box. ?When run that way, windows is almost
    usable...

    --
    Grant Edwards
    <snip>

    True, but when I'm using Cygwin, that means I'm at work and don't have
    a non-MS OS available. Of course I can open an ssh session to my home
    machine for sanity (or kicking off a torrent download at home), but I
    don't have a *nix-based OS at the day job. Lanching DSL embedded to
    use the terminal seems a bit much. ^_^

    Shawn
  • Grant Edwards at May 6, 2009 at 6:56 pm

    On 2009-05-06, Shawn Milochik wrote:

    That way, you can basically use PuTTY to shell into your
    Windows box.
    Better yet, set up sshd in your Cygwin install, and then use
    whatever terminal you normally use on your Linux/MacOS box to
    ssh into the Cygwin box. ??When run that way, windows is almost
    usable...
    <snip>

    True, but when I'm using Cygwin, that means I'm at work and don't have
    a non-MS OS available.
    Ouch. That's too bad. I spent a few months doing a project
    for which the compiler was windows-only. I found that doing
    all of the editing, source-control, and testing on Linux and
    sshing into a Cygwin box to do the "make" was minimally
    painful.
    Of course I can open an ssh session to my home machine for
    sanity (or kicking off a torrent download at home), but I
    don't have a *nix-based OS at the day job. Lanching DSL
    embedded to use the terminal seems a bit much. ^_^
    Probably so.

    --
    Grant Edwards grante Yow! I want a VEGETARIAN
    at BURRITO to go ... with
    visi.com EXTRA MSG!!
  • Dave Angel at May 6, 2009 at 8:29 pm

    Tim Chase wrote:
    <div class="moz-text-flowed" style="font-family: -moz-fixed">> for
    windows this works:
    (can't cut and paste from a dos box!###%*&!!!)
    Depending on how it was spawned, you can either right-click in the
    window and choose Mark/Paste (when marking, use <enter> to terminate
    the selection; and selections are blockwise rectangular rather than
    linewise or characterwise). Alternatively, if you click on the system
    menu (the icon in the title-bar with
    resize/minimize/maximize/close/help), there should be an Edit submenu
    with the same options within.

    A pain, but at least feasible.

    HTH,

    -tkc
    Note that if you like copy/paste, you can turn on "Quick Edit" mode in
    your cmd.exe windows. From that same System menu on your DOS box,
    choose "Defaults". From the first tab that box, enable "Quick Edit"
    checkbox. This will change the default for subsequent DOS boxes. You
    can change it just for the current one by using Properties in the same
    system menu.
  • Norseman at May 6, 2009 at 11:28 pm

    Dave Angel wrote:
    Tim Chase wrote:
    <div class="moz-text-flowed" style="font-family: -moz-fixed">> for
    windows this works:
    (can't cut and paste from a dos box!###%*&!!!)
    Depending on how it was spawned, you can either right-click in the
    window and choose Mark/Paste (when marking, use <enter> to terminate
    the selection; and selections are blockwise rectangular rather than
    linewise or characterwise). Alternatively, if you click on the system
    menu (the icon in the title-bar with
    resize/minimize/maximize/close/help), there should be an Edit submenu
    with the same options within.

    A pain, but at least feasible.

    HTH,

    -tkc
    Note that if you like copy/paste, you can turn on "Quick Edit" mode in
    your cmd.exe windows. From that same System menu on your DOS box,
    choose "Defaults". From the first tab that box, enable "Quick Edit"
    checkbox. This will change the default for subsequent DOS boxes. You
    can change it just for the current one by using Properties in the same
    system menu.


    --
    http://mail.python.org/mailman/listinfo/python-list
    ====================

    HuMMMMMM - Dave's use of cmd.exe as different from Dos Box points out a
    miss name on my part. I should have said cmd.exe originally.

    Yes - I use dosemu on Linux Slackware 10.2 with enlightenment 16.2 and
    swipe/paste works as it should. (Of course gpm is loaded. That's a must. :)

    I have been cutting back. Used to have 6 keyboards going at once. (well
    in packet passing mode shall we say? When computers were slower. :)
    Down to two close by and two across the way. One Solaris, two Linux, one
    Win XP. Gotta keep the Win machine nearby. It needs its daily crash. I
    have learned to stick to 'stock' setups or pay a heavy price at "show time".

    I tried the settings again just now.
    I did both Properties and Default and made sure they were set the same.
    I did the --- for icon --- and killed the open box and clicked the icon
    and swiped and pasted to wordpad. IT FINALLY WORKED!!!

    Hadn't intended to start such a rash of dialog, but I benefited too!

    Thanks guys!!!


    Steve
  • Mensanator at May 6, 2009 at 8:13 pm

    On May 6, 12:54 pm, Tim Chase wrote:
    for windows this works:
    (can't cut and paste from a dos box!###%*&!!!)
    Depending on how it was spawned, you can either right-click in
    the window and choose Mark/Paste (when marking, use <enter> to
    terminate the selection; and selections are blockwise rectangular
    rather than linewise or characterwise). Alternatively, if you
    click on the system menu (the icon in the title-bar with
    resize/minimize/maximize/close/help), there should be an Edit
    submenu with the same options within.

    A pain, but at least feasible.
    Less painful is to set the properties of the dos box:

    Edit Options:
    [x] Quick Edit mode

    And when prompted, do "(.) modify shortcut that started this window"

    After which, you can dispense with the menus (except when pasting),
    just select the text and hit <enter>.

    Makes a world of difference.
    HTH,

    -tkc
  • Dave Angel at May 6, 2009 at 8:46 pm

    Mensanator wrote:
    <snip>

    And when prompted, do "(.) modify shortcut that started this window"

    After which, you can dispense with the menus (except when pasting),
    just select the text and hit <enter>.
    To paste into a DOS box, once Quick Edit is enabled, use Right-Click.
    They keystrokes will be sent to the command editor. Note that the
    interpretation is rather literal, so be careful if copy/pasting more
    than one line, or a line that was wrapped.
  • Mensanator at May 6, 2009 at 9:49 pm

    On May 6, 3:46?pm, Dave Angel wrote:
    Mensanator wrote:
    <snip>
    And when prompted, do "(.) modify shortcut that started this window"
    After which, you can dispense with the menus (except when pasting),
    just select the text and hit <enter>.
    To paste into a DOS box, once Quick Edit is enabled, use Right-Click. ?
    They keystrokes will be sent to the command editor. ?Note that the
    interpretation is rather literal, so be careful if copy/pasting more
    than one line, or a line that was wrapped.
    Well I'll be dipped. Didn't know you could do that.

    Of course, since I learned how to call programs from the
    script and capture their StdOut, I don't have much call for
    cut/paste from dos windows. Hopefully, I'll remember that the
    next time I need it.
  • MRAB at May 6, 2009 at 11:15 pm

    Mensanator wrote:
    On May 6, 3:46 pm, Dave Angel wrote:
    Mensanator wrote:
    <snip>
    And when prompted, do "(.) modify shortcut that started this window"
    After which, you can dispense with the menus (except when pasting),
    just select the text and hit <enter>.
    To paste into a DOS box, once Quick Edit is enabled, use Right-Click.
    They keystrokes will be sent to the command editor. Note that the
    interpretation is rather literal, so be careful if copy/pasting more
    than one line, or a line that was wrapped.
    Well I'll be dipped. Didn't know you could do that.

    Of course, since I learned how to call programs from the
    script and capture their StdOut, I don't have much call for
    cut/paste from dos windows. Hopefully, I'll remember that the
    next time I need it.
    That's new to me too!

    You probably already know that if you drag-and-drop a file onto the
    window you get its path.
  • Mensanator at May 6, 2009 at 11:38 pm

    On May 6, 6:15?pm, MRAB wrote:
    Mensanator wrote:
    On May 6, 3:46 pm, Dave Angel wrote:
    Mensanator wrote:
    <snip>
    And when prompted, do "(.) modify shortcut that started this window"
    After which, you can dispense with the menus (except when pasting),
    just select the text and hit <enter>.
    To paste into a DOS box, once Quick Edit is enabled, use Right-Click. ?
    They keystrokes will be sent to the command editor. ?Note that the
    interpretation is rather literal, so be careful if copy/pasting more
    than one line, or a line that was wrapped.
    Well I'll be dipped. Didn't know you could do that.
    Of course, since I learned how to call programs from the
    script and capture their StdOut, I don't have much call for
    cut/paste from dos windows. Hopefully, I'll remember that the
    next time I need it.
    That's new to me too!

    You probably already know that if you drag-and-drop a file onto the
    window you get its path.
    Damn! I may just go back to using Python from the command prompt
    instead of using IDLE.

    On second thought, IDLE is way too useful for indenting, dedenting,
    commenting and uncommenting blocks of code. Can't go back to using
    Notepad.
  • Dave Angel at May 7, 2009 at 12:56 am

    Mensanator wrote:
    On May 6, 6:15 pm, MRAB wrote:

    Mensanator wrote:
    On May 6, 3:46 pm, Dave Angel wrote:

    Mensanator wrote:
    <snip>
    And when prompted, do "(.) modify shortcut that started this window"
    After which, you can dispense with the menus (except when pasting),
    just select the text and hit <enter>.
    To paste into a DOS box, once Quick Edit is enabled, use Right-Click.
    They keystrokes will be sent to the command editor. Note that the
    interpretation is rather literal, so be careful if copy/pasting more
    than one line, or a line that was wrapped.
    Well I'll be dipped. Didn't know you could do that.

    Of course, since I learned how to call programs from the
    script and capture their StdOut, I don't have much call for
    cut/paste from dos windows. Hopefully, I'll remember that the
    next time I need it.
    That's new to me too!

    You probably already know that if you drag-and-drop a file onto the
    window you get its path.
    Damn! I may just go back to using Python from the command prompt
    instead of using IDLE.

    On second thought, IDLE is way too useful for indenting, dedenting,
    commenting and uncommenting blocks of code. Can't go back to using
    Notepad.

    When I started with Python, I was using Metapad for editing. Although
    it doesn't help with commenting-blocks, it's much better than Notepad
    for all purposes I used.

    Then I discovered Komodo. Although not cheap, it's a great IDE for my
    uses. And there's a free version called Komodo-Edit, which is missing
    the debugger but otherwise may be quite useful.
  • Shawn Milochik at May 7, 2009 at 1:51 am
    <snip>
    Damn! I may just go back to using Python from the command prompt
    instead of using IDLE.

    On second thought, IDLE is way too useful for indenting, dedenting,
    commenting and uncommenting blocks of code. Can't go back to using
    Notepad.
    <snip>


    You might want to check out iPython, then -- it's an interactive
    Python interpreter that's meant to be used as a shell environment. It
    has very useful help and auto-completion features.

    If you're just talking about an IDE, you might want to try TextMate if
    you're on a Mac. It's great. Notepad++ is good on Windows, but I
    haven't used it in Python much, so I don't know about its indentation
    features.
  • Dave Angel at May 7, 2009 at 12:15 am

    Mensanator wrote:
    On May 6, 3:46 pm, Dave Angel wrote:

    Mensanator wrote:
    <snip>

    And when prompted, do "(.) modify shortcut that started this window"

    After which, you can dispense with the menus (except when pasting),
    just select the text and hit <enter>.
    To paste into a DOS box, once Quick Edit is enabled, use Right-Click.
    They keystrokes will be sent to the command editor. Note that the
    interpretation is rather literal, so be careful if copy/pasting more
    than one line, or a line that was wrapped.
    Well I'll be dipped. Didn't know you could do that.

    Of course, since I learned how to call programs from the
    script and capture their StdOut, I don't have much call for
    cut/paste from dos windows. Hopefully, I'll remember that the
    next time I need it.
    As long as we're in Quick Edit mode, another trick is that you can
    double-click on a "word" in a DOS box to select it and copy to
    clipboard. Obviously it isn't always the exact string you want, but
    sometimes it beats dragging the mouse over the text.
  • Scott David Daniels at May 6, 2009 at 10:41 pm

    Dave Angel wrote:
    Mensanator wrote:
    ... After which, you can dispense with the menus (except when pasting),
    just select the text and hit <enter>.
    To paste into a DOS box, once Quick Edit is enabled, use Right-Click.
    They keystrokes will be sent to the command editor. Note that the
    interpretation is rather literal, so be careful if copy/pasting more
    than one line, or a line that was wrapped.
    Also, you can type into the cmd window:

    Alt-Space E P

    Alt-Space
    <get to menu>
    E
    <Edit submenu>
    P
    <Paste>

    --Scott David Daniels
    Scott.Daniels at Acm.Org
  • Norseman at May 6, 2009 at 11:10 pm

    Mensanator wrote:
    On May 6, 12:54 pm, Tim Chase wrote:
    for windows this works:
    (can't cut and paste from a dos box!###%*&!!!)
    Depending on how it was spawned, you can either right-click in
    the window and choose Mark/Paste (when marking, use <enter> to
    terminate the selection; and selections are blockwise rectangular
    rather than linewise or characterwise). Alternatively, if you
    click on the system menu (the icon in the title-bar with
    resize/minimize/maximize/close/help), there should be an Edit
    submenu with the same options within.

    A pain, but at least feasible.
    Less painful is to set the properties of the dos box:

    Edit Options:
    [x] Quick Edit mode

    And when prompted, do "(.) modify shortcut that started this window"

    After which, you can dispense with the menus (except when pasting),
    just select the text and hit <enter>.

    Makes a world of difference.
    HTH,

    -tkc
    --
    http://mail.python.org/mailman/listinfo/python-list
    ===================
    On a straight box - that doesn't work either.
    The select all does, but paste yanked something from hours ago.
    Yes - set as stated, closed and used icon to open box.

    MicroSoft still need to soften its hard head and join the 21st century.

    I love the ease of Linux.

    One thing we do get from using both OS's - our first release code is
    much more solid as a result.

    Steve
  • Dave Angel at May 7, 2009 at 12:29 am

    norseman wrote:
    <snip>
    On a straight box - that doesn't work either.
    The select all does, but paste yanked something from hours ago.

    <snip>
    Once you have Quick Edit enabled, paste will work using right-click. If
    it got something from hours ago, then that must be the last time you
    copied anything to the real clipboard. Note that some applications use
    a private clipboard to give extra features (like multiple clipboxes).
    But I suspect your real problem is you thought you did a copy to the
    clipboard from the DOS box, and you did not.

    When you drag the mouse over the box, you *select* text, but do not copy
    it to the clipboard. That doesn't happen till your right-click.

    Then *another* right-click without anything selected will insert that
    new text into the command line.

    Try the following on a DOS box (after enabling Quick Edit).
    Double-click on a "word". Then right click *twice* to get it to the
    command line.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouppython-list @
categoriespython
postedMay 6, '09 at 3:31p
activeMay 7, '09 at 1:51a
posts21
users9
websitepython.org

People

Translate

site design / logo © 2022 Grokbase