LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 07-17-2011, 08:19 AM   #1
Linux Chips
LQ Newbie
 
Registered: Jul 2011
Posts: 22

Rep: Reputation: Disabled
Question can't use ($) dollar sign in string ... php/fi 2.0.1


hi ... any one familiar with ancient php/fi 2.0.1
i have a bunch of ubnt nanostations M series (wireless access points/routers)... they use airOS (a fork of openwrt). it runs a custom firmware that i made using provided sdk. and the lighttpd uses php/fi 2.0.1.... this is (of course) used to serve the web configuration.

the problem: i need to use the ($) in a string but i couldn't. what i need to do is download some file from the internet using wget and have the pid of wget back to keep track of the process, then parse the output to the page:

Code:
$cmd = "wget $FileToDownload -O $file > $wget_log 2>&1 & echo \$!";
$pid = exec($cmd);
echo $pid;
what i get from the last echo is (\$!) not the pid. i trid removing the escape (\) then i get only (!). i also tried
Code:
"wget $FileToDownload -O $file > $wget_log 2>&1 & echo " + '$!'
then i get 36... the dot (.) operator between two string produces parse error!! e.g. "...echo ".'$!'

running the command from the terminal gives correct pid... tried manually putting the download part in a file and running it from php and it worked when i do some thing like:
Code:
$pid = exec("/tmp/download.sh")
echo $pid
but the proble with this is the same, can't write the script from php (same $ problem) and can't use a permanent one cause the file to download will change periodically

any ideas??!!

regards
 
Old 07-17-2011, 09:31 PM   #2
kbp
Senior Member
 
Registered: Aug 2009
Posts: 3,790

Rep: Reputation: 653Reputation: 653Reputation: 653Reputation: 653Reputation: 653Reputation: 653
How about this ? (untested)
Code:
$cmd = "wget $FileToDownload -O $file > $wget_log 2>&1";
$pidcmd = "pgrep -f wget.*$FileToDownload";
$pid = exec($pidcmd);
echo $pid;
 
Old 07-18-2011, 06:28 AM   #3
Linux Chips
LQ Newbie
 
Registered: Jul 2011
Posts: 22

Original Poster
Rep: Reputation: Disabled
hi...
thanks for the replay

Quote:
How about this ? (untested)

Code:
$cmd = "wget $FileToDownload -O $file > $wget_log 2>&1";
$pidcmd = "pgrep -f wget.*$FileToDownload";
$pid = exec($pidcmd);
echo $pid;
do you mean?
Code:
$cmd = "wget $FileToDownload -O $file > $wget_log 2>&1";
exec($cmd);
$pidcmd = "pgrep -f wget.*$FileToDownload";
$pid = exec($pidcmd);
echo $pid;
in the first case i get a pid that is not existed!!! the second i get the correct pid plus 1 (not always), and if i try to kill that pid from the command line i get the error telling that there is no such process.
 
Old 07-18-2011, 08:15 AM   #4
onebuck
Moderator
 
Registered: Jan 2005
Location: Central Florida 20 minutes from Disney World
Distribution: SlackwareŽ
Posts: 13,927
Blog Entries: 45

Rep: Reputation: 3159Reputation: 3159Reputation: 3159Reputation: 3159Reputation: 3159Reputation: 3159Reputation: 3159Reputation: 3159Reputation: 3159Reputation: 3159Reputation: 3159
Moved: This thread is more suitable in <Programming> and has been moved accordingly to help your thread/question get the exposure it deserves.
 
Old 07-18-2011, 09:29 AM   #5
Linux Chips
LQ Newbie
 
Registered: Jul 2011
Posts: 22

Original Poster
Rep: Reputation: Disabled
solved... kind of

thanks onebuck ...

well i found the problem with kbp's method (thank you, i did non know about it)... the pid returned was the one for the pgrep it self, although the man page say it dose not (weird). well it dose not return self pid from cli, only from within the php!!

i add (^) to the regex matching and it worked, now it looks like this
Code:
$cmd = "wget $FileToDownload -O $file > $wget_log 2>&1";
exec($cmd);
$pidcmd = "pgrep -f ^wget.*$FileToDownload";
$pid = exec($pidcmd);
echo $pid;
not clean as the "echo $!" thing (which works perfectly on my fedora box and php5), but it dose the trick.
still... can't i use the ($) in a string??? is it the php2 that dose not support it, or i am doing some thing wrong!!?? or may be it is the way the os is built... btw it uses busybox if that makes difference
 
Old 07-18-2011, 09:37 AM   #6
onebuck
Moderator
 
Registered: Jan 2005
Location: Central Florida 20 minutes from Disney World
Distribution: SlackwareŽ
Posts: 13,927
Blog Entries: 45

Rep: Reputation: 3159Reputation: 3159Reputation: 3159Reputation: 3159Reputation: 3159Reputation: 3159Reputation: 3159Reputation: 3159Reputation: 3159Reputation: 3159Reputation: 3159
Hi,

Just a few links to aid you to gaining some understanding;



1 Linux Documentation Project
2 Rute Tutorial & Exposition
3 Linux Command Guide
4 Bash Beginners Guide
5 Bash Reference Manual
6 Advanced Bash-Scripting Guide
7 Linux Newbie Admin Guide
8 LinuxSelfHelp
9 Utimate Linux Newbie Guide
10 Linux Home Networking
11 Virtualization- Top 10

The above links and others can be found at 'Slackware-Links'. More than just SlackwareŽ links!
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
zsh PS1, dollar sign in the beginning, why? Mr. Alex Linux - Newbie 1 01-25-2011 09:48 AM
[SOLVED] Dollar sign in zsh Mr. Alex Linux - Newbie 3 01-24-2011 10:48 AM
Making grep find files containing '$' (the dollar sign char). stf92 Linux - Newbie 9 12-08-2010 11:16 AM
string with dollar symbol in url parameters in php stranger_6_7 Linux - General 9 09-03-2008 04:42 PM
Minus sign in printf format string doesn't work. zebela Linux - Newbie 4 06-13-2008 01:32 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 06:21 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration