/    Sign up×
Community /Pin to ProfileBookmark

using exec() function

I’m adapting someone else’s code to run on my site.

A C program should be run using exec() but it seems to not work.

The code is like this:

[code=php]
$_pg = $_SERVER[‘DOCUMENT_ROOT’].”/path/cprogram”;
$_p = $_params[‘p’] * 1000;
$_stmt = “{$_pg} 3 {$_p} {$_params[‘t’]}”;
$_line = exec($_stmt);
[/code]

When I print_r($_line) it is an empty array, meaning its not working. The original code works on the same server, but I had to change a lot of that code.

I think the problem is with the line stating $_stmt. I havent seen that syntax of “{…}” before. Is there another way to write that?

to post a comment
PHP

5 Comments(s)

Copy linkTweet thisAlerts:
@NightShift58Mar 15.2007 — [code=php]...$_pg = $_SERVER['DOCUMENT_ROOT']."/path/cprogram";
$_p = $_params['p'] * 1000;
$_stmt = $_pg . " 3 " . $_p . " " . $_params['t'];
$_line = array();
exec($_stmt, &$_line, &$_success);
[/code]
Copy linkTweet thisAlerts:
@mameha1977authorMar 15.2007 — Hmm still not working.

If I use this code I get this error:

[code=php]$_pg = $_SERVER['DOCUMENT_ROOT']."/path/cprogram";
$_p = $_params['p'] * 1000;

$_stmt = $_pg . " 3 " . $_p . " " . $_params['t'];
$_line = array();
exec($_stmt, &$_line, &$_success);
$_info = mb_split(",", $_line);[/code]


Warning: mb_split() expects parameter 2 to be string, array given in C:wampwwwpathtopage.php on line x[/QUOTE]

If I print_r($_line) it is an empty array.

The original code uses:
[code=php]$_line = exec($_stmt); [/code]
...so I think exec returns a value which has to be passed into $_line.
Copy linkTweet thisAlerts:
@mameha1977authorMar 15.2007 — Its OK I got it to work. your code was ok. my path to the script was wrong.
Copy linkTweet thisAlerts:
@NightShift58Mar 15.2007 — All's well that ends well!
×

Success!

Help @mameha1977 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.7,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...