Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7278245
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T22:50:55+00:00 2026-05-28T22:50:55+00:00

I am just starting with python so I am struggling with a quite simple

  • 0

I am just starting with python so I am struggling with a quite simple example. Basically I want pass the name of an executable plus its input via the command line arguments, e.g.:

python myprogram refprogram.exe refinput.txt

That means when executing myprogram, it executes refprogram.exe and passes to it as argument refinput. I tried to do it the following way:

import sys, string, os
print sys.argv

res = os.system(sys.argv(1)) sys.argv(2)
print res

The error message that I get is:

res = os.system(sys.argv(1)) sys.argv(2)
                           ^
SyntaxError: invalid syntax

Anyone an idea what I am doing wrong?

I am running Python 2.7

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T22:50:55+00:00Added an answer on May 28, 2026 at 10:50 pm

    This line

    res = os.system(sys.argv(1)) sys.argv(2)
    

    Is wrong in a couple of ways.

    First, sys.argv is a list, so you use square brackets to access its contents:

    sys.argv[1]
    sys.argv[2]
    

    Second, you close out your parentheses on os.system too soon, and sys.argv(2) is left hanging off of the end of it. You want to move the closing parenthesis out to the very end of the line, after all of the arguments.

    Third, you need to separate the arguments with commas, a simple space won’t do.

    Your final line should look like this:

    res = os.system(sys.argv[1], sys.argv[2])
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm just starting out learning python with GEdit plus various plugins as my IDE.
Just starting to figure Python out. I've read this question and its responses: Is
I'm just starting on Python and maybe I'm worrying too much too soon, but
I'm a C++ programmer just starting to learn Python. I'd like to know how
I've been working with python for a while now and am just starting to
I've done some Python but have just now starting to use Ruby I could
I'm just starting with Python on Google App Engine building a contact database. What
I am just starting to learn Python, but I have already run into some
I'm just starting to learn python... so bear with me please Why is it
Just starting out to program in python and I'm having the following issue. I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.