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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T05:37:52+00:00 2026-06-04T05:37:52+00:00

I have recently made a program that is supposed to take two environment variables,

  • 0

I have recently made a program that is supposed to take two environment variables, insert them into a string, then send the string to popen, and it works fine most of the time, but for some reason it will randomly not execute every so often, so I was just wondering if anyone saw any possible errors or mistakes that I am making?

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main(int argc, char *argv[], char *envp[]) {

   char *output;
   char *ccode;
   char *command;
   char *log;

   command = malloc(1024);
   log = malloc(1024);
   const char *parg = getenv("MCEXEC_ARGS");
   const char *pname = getenv("MCEXEC_PLAYERNAME");

   if(strcmp(parg,"")==0) {
       output = "Usage: /staff <message>";
       printf( "%s\n", output );
       return 0;
   }

   freopen("/dev/null","w",stdout);

   if (argv[1] == NULL) {
       snprintf(command, 1024,
                "/home/minecraft/remoteclient01a.py 'sendmsgtogroup staff §f(§bSTAFF§f) <%s§f> %s'",
                pname, parg);
       snprintf(log, 1024,
                "/home/minecraft/remoteclient01a.py 'savetolog info staffmsg: <%s> %s'",
                pname, parg);
   }
   else if (strcmp(argv[1],"me")==0) {
       snprintf(command, 1024,
                "/home/minecraft/remoteclient01a.py 'sendmsgtogroup staff §f(§bSTAFF§f) * %s§f %s'",
                pname, parg);
       snprintf(log, 1024,
                "/home/minecraft/remoteclient01a.py 'savetolog info staffmsg: * %s %s'",
                pname, parg);
   }

   popen(command, "w");
   popen(log, "w");

   free(command);
   free(log);

   return 0;
}
  • 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-04T05:37:56+00:00Added an answer on June 4, 2026 at 5:37 am

    Well …

    • You’re not checking that malloc() succeeds.
    • You’re not handling that the environment variables might not exist.
    • You’re calling strcmp() on a pointer that might be NULL; which might kill your program right there.
    • You’re not checking that the file open succeeds.
    • You have weird § characters in the commands strings, not sure if those are intended.
    • You’re not checking if popen() succeeds.
    • I don’t think your usage of popen() makes sense; you’re not using the pipes once opened.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So I have a website that I recently made changes to, and one of
Alright so I have recently made the decision to put every string in my
I have recently made a new homepage for my company so that employees can
I have an iPhone app that is using CoreData. I recently made some minor
Hi I have recently made this script to rename files I scan for work
I have recently started reading about dependency injection and it has made me rethink
I have made Catifier.com recently, and once the user sets their own background image,
I have recently run into a particularly sticky issue regarding committing the result of
I recently made some changes to my development environment and came across a problem.
I have written a converter that takes openstreetmap xml files and converts them to

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.