473,785 Members | 2,924 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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?

Jul 18 '07 #1
5 1679
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?

Jul 19 '07 #2
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.

Jul 19 '07 #3
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?

Jul 19 '07 #4
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.

Jul 22 '07 #5
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
http://tobyinkster.co.uk/blog/2007/0...table-parsing/
Jul 22 '07 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
11592
by: Sandie Towers | last post by:
We use a number of similar databases and frequently create a new database using a backup restore of another similar database. We try to keep changes between databases in _Additional tables - like Account Additional, Sale_Additional so most tables stay the same. The latest restored database (I'll call it DBaseA) is behaving differently in VB6 code and I need help trying to make it work. I have been using use an ADODB.Command to execute...
20
2107
by: CoolPint | last post by:
While I was reading about const_cast, I got curious and wanted to know if I could modify a constant variable through a pointer which has been "const_cast"ed. Since the pointer would be pointing to the constant variable and if I changed the value through the pointer, the constant variable should have been modified. Well, that's what I thought until I wrote the following and run it. #include <iostream> using std::cout; using std::endl;
3
2090
by: Robert | last post by:
Hi, I am kinda new to c and i've encountered a problem with program because i need to change a constant. I ofcourse don't want to change a constant so is there any way to convert a constant to a variable? I've tried something with malloc but it didn't work for me. Here's what i tried: char *url; char *filename; char *tmpstring; url = strtok(header, " ");
46
2741
by: James Harris | last post by:
Before I embark on a new long-term project I'd appreciate your advice on how to split up long names. I would like to keep the standards for command names the same as that for variable names. Looking at the examples below, which ones seem better? Straight names echoclient lastcharoffset helloworld Internal underscores
2
2809
by: timpera2501 | last post by:
I am a newb to OOP programming and I'm only just starting with C#. I've done a TON of reading lately, and I'm currently in the process of modifying some of the function provided by the "TimeTracker Start-up Kit" for my needs. ****** BEGINING OF TIME TRACKER SUMMARY ***** First, in the "TimeTracker Start-Up Kit" they appear to have tried to set it up so that it can be expanded to any number of different datasource types (SQL, Access,...
12
7916
by: Jim Rodgers | last post by:
I have a big asp file that has an error under certain conditions -- totally repeatable. However, it only fails when I set response.buffer = True at the top. WHen I set it False in order to debug it, it works every time! I even set it to True, but did a .Flush just before the error, and the error won't happen. It only happens when response.buffer is True and no .response.flush is issued. The error is a string variable turns-up empty...
14
3206
by: Vlad Dogaru | last post by:
Hello, I am trying to learn C, especially pointers. The following code attempts to count the appearences of each word in a text file, but fails invariably with Segmentation Fault. Please help me out, I've already tried all my ideas. Also, please do comment on my coding style or other aspects. Thank you. #include <stdio.h> #include <string.h>
10
6110
by: jimmy | last post by:
Hi again, sorry for posting two questions so close together but im working on a school project which is due in soon and running into some difficulties implementing the database parts. I have the code below which when executed generates the following error message: 'There is already an open datareader with this command which must be closed first' Private Sub MainMenu_Load(ByVal sender As System.Object, ByVal e As
22
8435
by: Laura T. | last post by:
In the following example, c# 2.0 compiler says that a3 and ret are used before assigned. as far as I can see, definite assignment is made. If I add finally { ret = true; a3 = "b3";
0
9643
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10147
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9947
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7494
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6737
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5379
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5511
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3645
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2877
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.