Command fails if I use variable instead of string constant

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • qazwart

    Command fails if I use variable instead of string constant

    I am reading from a "cvs rlog" command, and I need both the STDOUT and
    STDERR. Unfortunately, something very strange is happening. If I do
    this:

    $cmd = "$cvs_cmd -q rlog -NS -r$from_label::$ to_label neo 2>&1"; //
    Hard coded module
    DEBUG ("if (!($cvs_fh = popen(\"$cmd\", 'r'))) {");
    if (!($cvs_fh = popen("$cmd", 'r'))) {
    generate_error( "Canot open command \"$cmd\" for reading");
    }
    $exam_file_flag = false;
    $inside_revisio n_flag = false;
    $inside_comment _flag = false;
    print "Generating Initial Release Information: ";
    flush();
    while($line = fgets($cvs_fh)) {
    DEBUG ("....line = \"$line\"");

    I get the combined STDOUT and STDERR in my while loop. However if I do
    this:

    $cvs_module = "neo"
    $cmd = "$cvs_cmd -q rlog -NS -r$from_label::$ to_label $cvs_module
    2>&1"; //Use variable for module
    DEBUG ("if (!($cvs_fh = popen(\"$cmd\", 'r'))) {");
    if (!($cvs_fh = popen("$cmd", 'r'))) {
    generate_error( "Canot open command \"$cmd\" for reading");
    }
    $exam_file_flag = false;
    $inside_revisio n_flag = false;
    $inside_comment _flag = false;
    print "Generating Initial Release Information: ";
    flush();
    while($line = fgets($cvs_fh)) {
    DEBUG ("....line = \"$line\"");

    I don't get STDERR in my while loop.

    Note the "DEBUG" line. This is a little routine I wrote to help me see
    what is going on. Here is the output of the DEBUG line in the first
    code example:

    DEBUG: if (!( = popen("/usr/local/bin/cvs -d :pserver:build@ aladdin:/
    tools/CVSROOT -q rlog -NS -rNEO-199::NEO-210 neo 2>&1", 'r'))) {

    Here is the output of the "DEBUG" line in the second code example:

    DEBUG: if (!( = popen("/usr/local/bin/cvs -d :pserver:build@ aladdin:/
    tools/CVSROOT -q rlog -NS -rNEO-199::NEO-210 neo 2>&1", 'r'))) {

    Is there something I should be looking for?

  • qazwart

    #2
    Re: Command fails if I use variable instead of string constant

    Okay, we figured this one out. When I did a "trim" on the $cvs_module
    variable, the problem cleared up. I was reading the $cvs_module from a
    file, and apparently, I didn't remove the "\n" from the end of the
    variable when I extracted the information I wanted. Because I was
    looking at it via a web page, the "\n" didn't show up.

    On Jul 18, 6:26 pm, qazwart <qazw...@gmail. comwrote:
    I am reading from a "cvs rlog" command, and I need both the STDOUT and
    STDERR. Unfortunately, something very strange is happening. If I do
    this:
    >
    $cmd = "$cvs_cmd -q rlog -NS -r$from_label::$ to_label neo 2>&1"; //
    Hard coded module
    DEBUG ("if (!($cvs_fh = popen(\"$cmd\", 'r'))) {");
    if (!($cvs_fh = popen("$cmd", 'r'))) {
    generate_error( "Canot open command \"$cmd\" for reading");
    }
    $exam_file_flag = false;
    $inside_revisio n_flag = false;
    $inside_comment _flag = false;
    print "Generating Initial Release Information: ";
    flush();
    while($line = fgets($cvs_fh)) {
    DEBUG ("....line = \"$line\"");
    >
    I get the combined STDOUT and STDERR in my while loop. However if I do
    this:
    >
    $cvs_module = "neo"
    $cmd = "$cvs_cmd -q rlog -NS -r$from_label::$ to_label $cvs_module
    2>&1"; //Use variable for module
    DEBUG ("if (!($cvs_fh = popen(\"$cmd\", 'r'))) {");
    if (!($cvs_fh = popen("$cmd", 'r'))) {
    generate_error( "Canot open command \"$cmd\" for reading");
    }
    $exam_file_flag = false;
    $inside_revisio n_flag = false;
    $inside_comment _flag = false;
    print "Generating Initial Release Information: ";
    flush();
    while($line = fgets($cvs_fh)) {
    DEBUG ("....line = \"$line\"");
    >
    I don't get STDERR in my while loop.
    >
    Note the "DEBUG" line. This is a little routine I wrote to help me see
    what is going on. Here is the output of the DEBUG line in the first
    code example:
    >
    DEBUG: if (!( = popen("/usr/local/bin/cvs -d :pserver:build@ aladdin:/
    tools/CVSROOT -q rlog -NS -rNEO-199::NEO-210 neo 2>&1", 'r'))) {
    >
    Here is the output of the "DEBUG" line in the second code example:
    >
    DEBUG: if (!( = popen("/usr/local/bin/cvs -d :pserver:build@ aladdin:/
    tools/CVSROOT -q rlog -NS -rNEO-199::NEO-210 neo 2>&1", 'r'))) {
    >
    Is there something I should be looking for?

    Comment

    • ZeldorBlat

      #3
      Re: Command fails if I use variable instead of string constant

      On Jul 18, 6:26 pm, qazwart <qazw...@gmail. comwrote:
      I am reading from a "cvs rlog" command, and I need both the STDOUT and
      STDERR. Unfortunately, something very strange is happening. If I do
      this:
      >
      $cmd = "$cvs_cmd -q rlog -NS -r$from_label::$ to_label neo 2>&1"; //
      Hard coded module
      DEBUG ("if (!($cvs_fh = popen(\"$cmd\", 'r'))) {");
      if (!($cvs_fh = popen("$cmd", 'r'))) {
      generate_error( "Canot open command \"$cmd\" for reading");
      }
      $exam_file_flag = false;
      $inside_revisio n_flag = false;
      $inside_comment _flag = false;
      print "Generating Initial Release Information: ";
      flush();
      while($line = fgets($cvs_fh)) {
      DEBUG ("....line = \"$line\"");
      >
      I get the combined STDOUT and STDERR in my while loop. However if I do
      this:
      >
      $cvs_module = "neo"
      $cmd = "$cvs_cmd -q rlog -NS -r$from_label::$ to_label $cvs_module
      2>&1"; //Use variable for module
      DEBUG ("if (!($cvs_fh = popen(\"$cmd\", 'r'))) {");
      if (!($cvs_fh = popen("$cmd", 'r'))) {
      generate_error( "Canot open command \"$cmd\" for reading");
      }
      $exam_file_flag = false;
      $inside_revisio n_flag = false;
      $inside_comment _flag = false;
      print "Generating Initial Release Information: ";
      flush();
      while($line = fgets($cvs_fh)) {
      DEBUG ("....line = \"$line\"");
      >
      I don't get STDERR in my while loop.
      >
      Note the "DEBUG" line. This is a little routine I wrote to help me see
      what is going on. Here is the output of the DEBUG line in the first
      code example:
      >
      DEBUG: if (!( = popen("/usr/local/bin/cvs -d :pserver:build@ aladdin:/
      tools/CVSROOT -q rlog -NS -rNEO-199::NEO-210 neo 2>&1", 'r'))) {
      >
      Here is the output of the "DEBUG" line in the second code example:
      >
      DEBUG: if (!( = popen("/usr/local/bin/cvs -d :pserver:build@ aladdin:/
      tools/CVSROOT -q rlog -NS -rNEO-199::NEO-210 neo 2>&1", 'r'))) {
      >
      Is there something I should be looking for?
      Before running the command echo out the value of $cmd to make sure it
      is what you think it is.

      Comment

      • petersprc

        #4
        Re: Command fails if I use variable instead of string constant

        It shouldn't make a difference. Try setting error_reporting (E_ALL) to
        see if you have any errors.

        Missing a semi-colon here?

        $cvs_module = "neo"

        On Jul 18, 6:26 pm, qazwart <qazw...@gmail. comwrote:
        I am reading from a "cvs rlog" command, and I need both the STDOUT and
        STDERR. Unfortunately, something very strange is happening. If I do
        this:
        >
        $cmd = "$cvs_cmd -q rlog -NS -r$from_label::$ to_label neo 2>&1"; //
        Hard coded module
        DEBUG ("if (!($cvs_fh = popen(\"$cmd\", 'r'))) {");
        if (!($cvs_fh = popen("$cmd", 'r'))) {
        generate_error( "Canot open command \"$cmd\" for reading");
        }
        $exam_file_flag = false;
        $inside_revisio n_flag = false;
        $inside_comment _flag = false;
        print "Generating Initial Release Information: ";
        flush();
        while($line = fgets($cvs_fh)) {
        DEBUG ("....line = \"$line\"");
        >
        I get the combined STDOUT and STDERR in my while loop. However if I do
        this:
        >
        $cvs_module = "neo"
        $cmd = "$cvs_cmd -q rlog -NS -r$from_label::$ to_label $cvs_module
        2>&1"; //Use variable for module
        DEBUG ("if (!($cvs_fh = popen(\"$cmd\", 'r'))) {");
        if (!($cvs_fh = popen("$cmd", 'r'))) {
        generate_error( "Canot open command \"$cmd\" for reading");
        }
        $exam_file_flag = false;
        $inside_revisio n_flag = false;
        $inside_comment _flag = false;
        print "Generating Initial Release Information: ";
        flush();
        while($line = fgets($cvs_fh)) {
        DEBUG ("....line = \"$line\"");
        >
        I don't get STDERR in my while loop.
        >
        Note the "DEBUG" line. This is a little routine I wrote to help me see
        what is going on. Here is the output of the DEBUG line in the first
        code example:
        >
        DEBUG: if (!( = popen("/usr/local/bin/cvs -d :pserver:build@ aladdin:/
        tools/CVSROOT -q rlog -NS -rNEO-199::NEO-210 neo 2>&1", 'r'))) {
        >
        Here is the output of the "DEBUG" line in the second code example:
        >
        DEBUG: if (!( = popen("/usr/local/bin/cvs -d :pserver:build@ aladdin:/
        tools/CVSROOT -q rlog -NS -rNEO-199::NEO-210 neo 2>&1", 'r'))) {
        >
        Is there something I should be looking for?

        Comment

        • qazwart

          #5
          Re: Command fails if I use variable instead of string constant

          On Jul 19, 12:33 pm, ZeldorBlat <zeldorb...@gma il.comwrote:
          Before running the command echo out the value of $cmd to make sure it
          is what you think it is.
          That's what I did with the "DEBUG" line. Here it is printing out from
          my code when "neo" is hard coded:

          DEBUG: if (!( = popen("/usr/local/bin/cvs -d :pserver:build@ aladdin:/
          tools/CVSROOT -q rlog -NS -rNEO-199::NEO-210 neo 2>&1", 'r'))) {

          And, here is the second example when "neo" was read in from a
          variable:

          DEBUG: if (!( = popen("/usr/local/bin/cvs -d :pserver:build@ aladdin:/
          tools/CVSROOT -q rlog -NS -rNEO-199::NEO-210 neo 2>&1", 'r'))) {

          See the difference? Neither did I. If I did this in Perl on a
          terminal, I'd see the NL, but in HTML, NLs and multiple spaces aren't
          normally displayed in the browser.

          I had a colleague recommend that I print out the value of
          "$cvs_modul e", and I had put quotes around it. That displayed as:

          DEBUG: $cvs_module = "neo "

          The "space" on the end clued me in that this might be an issue, and
          sure enough, when I "trimmed" $cvs_module, the program worked.

          I did learn one lesson: My "DEBUG" function needs to surround the
          output with <pre></pretags. That way, I would have seen the NL in
          the output.
          On Jul 18, 6:26 pm, qazwart <qazw...@gmail. comwrote:
          >
          >
          >
          I am reading from a "cvs rlog" command, and I need both the STDOUT and
          STDERR. Unfortunately, something very strange is happening. If I do
          this:
          >
          $cmd = "$cvs_cmd -q rlog -NS -r$from_label::$ to_label neo 2>&1"; //
          Hard coded module
          DEBUG ("if (!($cvs_fh = popen(\"$cmd\", 'r'))) {");
          if (!($cvs_fh = popen("$cmd", 'r'))) {
          generate_error( "Canot open command \"$cmd\" for reading");
          }
          $exam_file_flag = false;
          $inside_revisio n_flag = false;
          $inside_comment _flag = false;
          print "Generating Initial Release Information: ";
          flush();
          while($line = fgets($cvs_fh)) {
          DEBUG ("....line = \"$line\"");
          >
          I get the combined STDOUT and STDERR in my while loop. However if I do
          this:
          >
          $cvs_module = "neo"
          $cmd = "$cvs_cmd -q rlog -NS -r$from_label::$ to_label $cvs_module
          2>&1"; //Use variable for module
          DEBUG ("if (!($cvs_fh = popen(\"$cmd\", 'r'))) {");
          if (!($cvs_fh = popen("$cmd", 'r'))) {
          generate_error( "Canot open command \"$cmd\" for reading");
          }
          $exam_file_flag = false;
          $inside_revisio n_flag = false;
          $inside_comment _flag = false;
          print "Generating Initial Release Information: ";
          flush();
          while($line = fgets($cvs_fh)) {
          DEBUG ("....line = \"$line\"");
          >
          I don't get STDERR in my while loop.
          >
          Note the "DEBUG" line. This is a little routine I wrote to help me see
          what is going on. Here is the output of the DEBUG line in the first
          code example:
          >
          DEBUG: if (!( = popen("/usr/local/bin/cvs -d :pserver:build@ aladdin:/
          tools/CVSROOT -q rlog -NS -rNEO-199::NEO-210 neo 2>&1", 'r'))) {
          >
          Here is the output of the "DEBUG" line in the second code example:
          >
          DEBUG: if (!( = popen("/usr/local/bin/cvs -d :pserver:build@ aladdin:/
          tools/CVSROOT -q rlog -NS -rNEO-199::NEO-210 neo 2>&1", 'r'))) {
          >
          Is there something I should be looking for?
          >
          Before running the command echo out the value of $cmd to make sure it
          is what you think it is.

          Comment

          • Toby A Inkster

            #6
            Re: Command fails if I use variable instead of string constant

            qazwart wrote:
            I did learn one lesson: My "DEBUG" function needs to surround the
            output with <pre></pretags. That way, I would have seen the NL in
            the output.
            Your browser's "View Source" capability should have clued you in too.

            --
            Toby A Inkster BSc (Hons) ARCS
            [Geek of HTML/SQL/Perl/PHP/Python/Apache/Linux]
            [OS: Linux 2.6.12-12mdksmp, up 31 days, 13:59.]

            Parsing an HTML Table with PEAR's XML_HTTPSax3

            Comment

            Working...