简体   繁体   中英

Running a javascript function from .cs file?

I have a page file (aspx) and a (.cs file) where the user can input some rules to block or unblock lines of production. When the user finishes making any changes, he/she presses a buuton to save the data. First it makes a .txt file with all the rules that were made or changed.

After that I need to execute a .exe file (made in Python) that takes this information and makes another text file by reading all the lines of production and all the orders (2 other files) to Block productions in certains lines. This is already done.

My problem is that I can't execute this .exe file. I have tried with this code in the .cs file

ScriptManager.RegisterStartupScript(this, GetType(), "blockinglines", "BlockLine()", true);

And BlockLine function is this

<script>
    function BlockLine(){
        var shell = new ActiveXObject("WScript.Shell");               
        var bat = "\"C:\\inetpub\\wwwroot\\BlockLine\\Bin\\dist\\BLines.exe\" ";
        shell.Run(bat);
    }
</script>

But I can't run it. Is there any other solution to make this or an error I have made in the code??

Replace this:

ScriptManager.RegisterStartupScript(this, GetType(), "blockinglines", "BlockLine()", true);

With this:

Process.Start(@"C:\inetpub\wwwroot\BlockLine\Bin\dist\BLines.exe");

Then get rid of the script section entirely. You may also need to add a reference to System.Diagnostics .

And remember that this only works when you want your BLines program to run on the web server. If you want this to run on the browser, you're completely out of luck, and for good reason.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM