I am having a Perl and a CGI file through which I want to fetch data from database. I've a UI where I am trying to use AJAX call which will hit the perl (.pl) or (.cgi) file and get the response in JSON. I've checked the perl/cgi file by running through command prompt and it works fine. This is how I am running my code in command prompt:
D:\>PerlExecutables\strawberry_32\perl\bin\perl.exe C:\Users\UserXYZ\Desktop\PerlExamples\test.cgi
The reason is I cannot do any kind of installation on my machine and also I don't want to run it through server like Apache or IIS.
How can this be achieved? Is there any way to make the script work in AJAX by passing the perl.exe path for execution or Any other alternatives?
Thanks!
One way to do this is to use Plack::App::CGIBin. It allows you to mount CGI scripts as apps with the PSGI/Plack protocol.
use Plack::App::CGIBin;
use Plack::Builder;
my $app = Plack::App::CGIBin->new(root => "/path/to/cgi-bin")->to_app;
builder {
mount "/cgi-bin" => $app;
};
Save that as myapp.psgi (or whatever your stuff is called) and run it like this:
$ plackup myapp.psgi
By default it will open up a server on port 3000 on localhost. You will need to be able to install Perl modules. Since you have Strawberry Perl that shouldn't be a problem. In the worst case, just use a local::lib.
You will also need to be able to open a port for listening. If you cannot there is no other solution than to get an admin to install you an actual full-scale web server.
The PSGI protocol and the Plack tools are a simple, easy to use replacement for CGI. They allow you to be very flexible while making it easy to have persistently running large applications.
Related
So im building app based on Express and using Prisma ORM. What i need is to SSH to a server, open up express.js console and create new db entry using prisma. Something similar to python manage.py shell for Django or rails console for Rails. Is there a solution for this of any kind?
Like I pointed in the comment there is a way ( kind of ) to get access to a running express instance. If that's all you need follow:
How can I open a console to interact with Express app?
Express doesn't exactly have a feature like rails console which is a framework feature in that case.
That said, I question the long term implication of this approach. If you really just need to seed some data, write an "init" script, and call it after you ssh into a server or using some CI/CD approach. This is more re-usable, since you can even pass a json file to the script to load dynamic data.
Also, Prismajs has an official way to seed the data ( if that's what you need) that you can leverage:
https://www.prisma.io/docs/guides/database/seed-database
UPDATE:
If you are able to run to code on your machine and point the remote database, then you can use node --inspect to debug in a chrome console. Which should give you about the same effect as a rails REPL
https://medium.com/#tbernardes/debugging-nodejs-with-chrome-inspector-devtools-1cd2ef323b5e
Using Codeigniter 2.2.0 for my project. Is $this->input->is_cli_request() validation is necessary for a cron job?
It is recommended to protect your cronjob not to execute when someone type the URL in their browser. However if you don't have any problem running your cronjob invoked by anyone then can avoid this check.
Refer https://ellislab.com/codeigniter/user-guide/general/cli.html for more details.
It recommented to run cron jobs with command line.
There are many reasons for running CodeIgniter from the command-line, but they are not always obvious.
Run your cron-jobs without needing to use wget or curl
Make your cron-jobs inaccessible from being loaded in the URL by checking for $this->input->is_cli_request()
Make interactive "tasks" that can do things like set permissions, prune cache folders, run backups, etc.
Integrate with other applications in other languages. For example, a random C++ script could call one command and run code in your models!
More info read here
But you also can prevent calling from URL in your server.
What is the best and most straighforward way to start a GUI application via a HTTP request?
This question is specific to a windows server and the GUI application is likely to be running as the local SYSTEM user. The HTTP request will be from outside of the servers network i.e. over the web.
I've tried making use of PHP and failed miserably, anything else that I can try?
Thanks all
Update
I tried the perl suggestion but it seems to run the app in the background:
#!C:/Perl/bin/perl.exe
print "Content-Type: text/html\n\n";
$ExecString = 'Start C:/www/csharp/Test.exe 8998 "Test Message"';
exec $ExecString;
Create a CGI binary. Run it from the web-server. Have the binary start your application.
A Perl script will do the job, too.
The CGI/perl/whatever will need to have appropriate local permissions, or the OS will forbid it to start an application.
Is there way to invoke a CakePHP console shell on server without shell access? I have written a shell for performing some once off (and hence not a cron task) post DB upgrade tasks.
I could always just copy the logic into a temporary controller, call its actions via http and then delete it, but was wondering if there was a better way to go about it.
It seems that this is a one off script you might want to typically be running after DB updates right?
If that's the case, you can make it part of your "DB update script"
If you use anything like capistrano, you can include there too.
In all cases, if you don't want to touch the shell, I agree that having a controller to call the console code (or any php file running exec() as mentioned previously) would do the trick.
Also, if you want to run it just once and have it scheduled - don't forget that you have the "at" command (instead of cron) which will run it at that scheduled date (see http://linux.about.com/library/cmd/blcmdl1_at.htm)
Hope it helps,
Cheers,
p.s: if its a console shell and you don't want to run it from the console, then just don't make it a console shell.
I have to agree with elvy. Since this is something that you need to do once in a while after other events have happened, why not just create an 'admin' area for your application and stick code for that update in there?
you may be able to use php's exec function to call it from any old php script.
http://www.php.net/exec
For a windows script I am writing, I need to detect if the machine has Apache 2.2 installed, and to find the application path.
One solution I came up with is to wget http://localhost:8080/server-info and parse the root and the config file from it. This would fail if the server does not use port 8080
Another option would be to call “sc qc Apache2.2” and to parse the returning string. This would fail if the server is not installed as a service, or is using a different name.
Is there any better way to do that?
Not a lot of great options if they didn't install it using the installer. If they used the MSI/installer, you can check the registry:
HKEY_LOCAL_MACHINE\SOFTWARE\Apache Software Foundation\Apache\2.2.2\ServerRoot
HKEY_CURRENT_USER\SOFTWARE\Apache Software Foundation\Apache\2.2.2\ServerRoot
You can also check the running process list:
WMIC PROCESS get Caption,Commandline,Processid
Look for the appropriate EXE. If for some reason you needed the port number, then use netstat and search for the appropriate port.
Also, when you say "a windows script", I am assuming you are using something modern and capable like Windows Scripting Host (my favorite) or PowerShell. Don't even bother with batch files.
As I recall, Apache writes some registry keys. If you know how to read them from a script, that might help.
uvdesk
Unable to locate the path on the server.
Try putting index.php after your helpdesk installation's site url or If you are using apache, make sure that mode_rewrite module is enabled and AllowOverride directive for document root is set to All/FileInfo in your server's configuration file.[enter code here][1]