Python Forum
Issue with command line arguments
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Issue with command line arguments
#1
So I'm having issues with my program command line arguments. In pycharm on windows it works great but when I go to linux it only takes arguments up to the first semicolon ";" and then pretends nothing exists beyond it.

My code:

inputs = []
for arg in sys.argv:
    inputs.append(arg)
then I call inputs.pop(0) to get what I need.

sample input is something like this:

load-policy sample.txt; add-attributes-to-permission PW role Student; check-permission Josie GradesFile ENV PW

In linux I run my file:

ABAC_engine.py load-policy sample.txt; add-attributes-to-permission PW role Student; check-permission Josie GradesFile ENV PW


and I have it print out everything saved in inputs....it only saves the first bit up until sample.txt (I'm supposing because of the semicolon)

Please help! Thank you!
Reply
#2
why do you need the semicolon there?
On linux shell semicolon is used to separate commands and each command will be executed regardless the outcome of the previous one
https://unix.stackexchange.com/a/159514
i.e. it's linux feature, not python issue

as to your code
inputs = sys.argv[::]
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#3
Thank you buran!

This helped me realize what was going on. It's rather long to explain but ultimately I used a makefile that worked with another file to take input from text files and feed it as arguments to my program and in doing so it took care of the parenthesis issue.

Thanks for your help with this, I didn't realize that linux separates commands via ; Very good thing to know!
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Accessing varying command line arguements Rakshan 3 290 Jul-28-2021, 03:18 PM
Last Post: snippsat
  SMTPSenderRefused: (530, b'5.7.0 Must issue a STARTTLS command first rhat398 0 434 Jul-13-2021, 06:24 PM
Last Post: rhat398
  How to input & output parameters from command line argument shantanu97 1 696 Apr-13-2021, 02:12 PM
Last Post: Larz60+
  Passing List of Objects in Command Line Python usman 7 1,112 Sep-27-2020, 03:45 PM
Last Post: ndc85430
  Taking Multiple Command Line Argument Input bwdu 6 1,592 Mar-29-2020, 05:52 PM
Last Post: buran
  python 3 from command line Dixon 1 784 Mar-01-2020, 08:35 PM
Last Post: snippsat
  execute linux command with arguments sivareddy 2 783 Feb-10-2020, 03:23 PM
Last Post: sivareddy
  Running linux command line apps... dbrdh 0 752 Jan-30-2020, 01:14 PM
Last Post: dbrdh
  command line input (arg parse) and data exchange Simba 7 1,952 Dec-06-2019, 11:58 PM
Last Post: Simba
  code works at command line but not in .py ridgerunnersjw 4 1,082 Sep-12-2019, 11:09 PM
Last Post: ridgerunnersjw

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020