You are here: Re: Command fails if I use variable instead of string constant « PHP Programming Language « IT news, forums, messages
Re: Command fails if I use variable instead of string constant

Posted by qazwart on 07/22/07 02:10

On Jul 19, 12:33 pm, ZeldorBlat <zeldorb...@gmail.com> wrote:
> 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_module", 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></pre> tags. That way, I would have seen the NL in
the output.

> On Jul 18, 6:26 pm, qazwart <qazw...@gmail.com> wrote:
>
>
>
> > 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_revision_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_revision_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.

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация