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 8749033
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T12:37:37+00:00 2026-06-13T12:37:37+00:00

I currently have a c++ Linux program that reads a parameter P from a

  • 0

I currently have a c++ Linux program that reads a parameter “P” from a file and loads it in RAM for further operations. The file has the following line :

P = 123

I would like the program to take P from shell input instead of the file. I am open to all options, as long as I can manually enter P while connected in SSH.
What I have in mind is something like an input prompt :

sudo myprogram start
enter P value : (I would manually enter "123" here)

Or maybe an argument :

sudo myprogram start 123

It must be simple to do but I do not know how, so any help is greatly appreciated !

  • 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-06-13T12:37:38+00:00Added an answer on June 13, 2026 at 12:37 pm

    If this is the only data that the file has then the file operation is needless.
    Simply pass 123 (or whatever) to your C++ program and convert the string into integer.

    Assuming you pass the integer as the second argument then:

    int  p = atoi(argv[2]);
    

    A better option is to use strtol:

    char *s, *ptr;
    
    s = argv[1];
    int p = strtol(s, &ptr, 10);
    

    If you can’t make changes to the C++ code then simply do:

    echo "P = 123" > file && myprogram start 
    

    If your file has more content and you can’t simply do echo then, replace the existing line with new value:

     sed -i "s/P = [0-9]*/P = 123/" file && myprogram start
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some code, that I'm currently porting from OS X to Linux (console
I have a possibly long running program that currently has 4 processes, but could
I have the following problem: I am writing a C++ program that has to
currently I'm writing little program that reads elf file header and prints some information
Currently have a drop down menu that is activated on a hover (from display:none
Currently I am working with a embedded system that has the Linux OS. I
I am new to EC2 and web development. Currently I have a Linux EC2
Versions of XMLStarlet found in current Linux distributions have a limit of 128 operations
I currently have a XSLT 2.0 Stylesheet that I am trying to remove empty
I currently have one project that currently contains multiple packages. These packages make up

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.