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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T10:41:45+00:00 2026-06-14T10:41:45+00:00

I am developing an application for work that allows the users to quickly set

  • 0

I am developing an application for work that allows the users to quickly set environment variables on a terminal basis. By setting the path in each terminal we ensure files with the same name in different directories aren’t causing application testing to be problematic. I am Using Qt to build the program which is c++ based and all the datatypes are foundationally the same.

I am using the following code to invoke commands in the terminal from which the application launches from using system(). I can run commands into the bash just fine with code; however, I run into a problem when I attempt to use a command with arguments. This is probably why source doesn’t seem to work right as the source command is followed by the filename. It would appear that I drop the argument appended after the bash command.

My Code:

void assignTerminalToPath(QString path)
{
    QString data = "";
    QString currentUsersHomeDirectory = QDir::homePath();
    QString tmpScriptLocation = currentUsersHomeDirectory;
    QByteArray ba;
    tmpScriptLocation += "/.tmpSourceFile";
    QFile tmpSourceFile(tmpScriptLocation);
    if(tmpSourceFile.open(QFile::WriteOnly | QFile::Truncate))
    {
        QTextStream output(&tmpSourceFile);
        data.append("export PATH=.:");
        data.append(path);
        data.append(":$PATH");
        output << QString("#!/bin/bash\n");
        output << data;
        tmpSourceFile.close();
    }
    data.clear();
    data.append("/bin/bash -c source ");
    data.append(tmpScriptLocation);
    ba = data.toLatin1();
    const char *cStr = ba.data();
    system(cStr);
}

Perhaps I’m not referencing bash correctly and I need something outside of -c?

Reference Execute shell/bash command using C/C++

Thanks for any help in advance!

  • 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-14T10:41:47+00:00Added an answer on June 14, 2026 at 10:41 am

    source is not a program that you can call, it is embedded bash command. It is designed to be processed by bash without invoking another copy of bash, such that environment variables can be changed in current bash copy.

    However, you cannot call source as part of system(). And even if you did succeed at that, its effects to change environment variables would be completely lost for caller app once system() has returned.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am developing a WPF application, that connects to several WCF services (that work
Hi I am developing an application that needs to work with a complex domain
I am developing an iPhone application that allows to basically click through a series
I'm currently developing a small rails application that allows me to manage my personal
I am currently developing an application to work with WAV files. I want to
I'm developing an application on two different machines (home and work) and while the
I'm developing a web application for a company which I work for. My team
I have 5 years of work experience in developing WEB and WIN application using
I'm developing a VB.NET 1.1 web application. All validation and RegEx controls work perfectly
I'm developing application with GWT 2 and would like to add float panel that

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.