27257

PHP system() args

I have the following code that executes a <strong>C++ program</strong> and <strong>outputs it</strong>:

<html> <head> <title>C++</title> </head> <body> <div><?php system("app.exe", $out); echo rtrim($out, "0"); ?></div> </body> </html>

How can I make it so that <strong>you can pass arguments to the c++ program</strong>, say like this...

If this was the <strong>c++</strong> program

#include <iostream> #include <string> int main(){ string input = getarg();//Not really a function, just one I kinda want to know cout << input; return 0; }

<strong>Could I do something like this?</strong>

<html> <head> <title>C++</title> </head> <body> <div><?php system("app.exe arg=hello-world", $out); echo rtrim($out, "0"); ?></div> </body> </html>

I <strong>don't know</strong> a lot of parts to this problem, <strong>I can execute the program</strong> but I just <strong>need to pass arguments.</strong>

Answer1:

You can pass the arguments space separated after the command like system("app.exe hello-world 2 3", $out);

in your c++ program

int main (int argc, char** argv) { // argv[1] will be pointing to "hello-world" // argv[2] => 2 // argv[3] => 3 }

Recommend

  • SQL Server 2005 FTS unexpected results
  • Can I bind multiple values as a single parameter using MYSQLI and PHP?
  • Mysql: How can I use RTRIM in my LOAD DATA INFILE query?
  • SQL - Find duplicate values and remove in a field
  • How do I fix “The program issued a command but the command length is incorrect.” error when calling
  • C++ String tokenisation from 3D .obj files
  • How dotnet build chooses the output name
  • JSR-330 support in Picocontainer : @Inject … @Named(\"xxx)
  • hide missing dates from x-axis ggplot2
  • aapt.exe'' finished with non-zero exit value 1
  • Creating a DropDownList
  • Who propagate bugfixes across branches (corporate development)?
  • Thread 1: EXC_BAD_ACCESS (code =1 address = 0x0)
  • Tamper-proof configuration files in .NET?
  • Code in Job's Script Block after Start-Process Does not Execute
  • Stop Bash Script if Hive Fails
  • How to add git credentials to the build so it would be able to be used within a shell code?
  • How to determine if there are bytes available to be read from boost:asio:serial_port
  • Scrapy recursive link crawler
  • FB SDK and cURL: Unknown SSL protocol error in connection to graph.facebook.com:443
  • Illegal mix of collations for operation for date/time comparison
  • req.body is undefined - nodejs
  • MySQL WHERE-condition in procedure ignored
  • Running a C# exe file
  • Symfony2: How to get request parameter
  • Display Images one by one with next and previous functionality
  • Why is the timeout on a windows udp receive socket always 500ms longer than set by SO_RCVTIMEO?
  • Upload files with Ajax and Jquery
  • Timeout for blocking function call, i.e., how to stop waiting for user input after X seconds?
  • Do I've to free mysql result after storing it?
  • Akka Routing: Reply's send to router ends up as dead letters
  • Is there a mandatory requirement to switch app.yaml?
  • A cron job substitute?
  • Windows forms listbox.selecteditem displaying “System.Data.DataRowView” instead of actual value
  • json Serialization in asp
  • Proper folder structure for lots of source files
  • Buffer size for converting unsigned long to string
  • Hits per day in Google Big Query
  • How does Linux kernel interrupt the application?
  • How to get Windows thread pool to call class member function?