Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Executing a program from the Shell
Message
De
26/12/2005 23:16:51
 
Information générale
Forum:
ASP.NET
Catégorie:
Autre
Divers
Thread ID:
01080875
Message ID:
01080909
Vues:
12
>What are you using to execute the file?
>
>You can use the Process class and capture the redirection output into the StandardOutput stream.
>
>The following demonstrates:
>
>
>public bool SetAcl()
>{
>    if (this.Pathname == null || this.Pathname == "")
>    {
>        ErrorMessage += "Path cannot be empty.";
>        return false;
>    }
>
>    // *** Strip off trailing backslash which isn't supported
>    if (this.Pathname.EndsWith("\\"))
>        this.Pathname = this.Pathname.Substring(0, this.Pathname.Length - 1);
>
>    string CommandLine = '"' + System.IO.Path.GetFullPath(this.Pathname) + '"' + " /C ";
>
>    if (this.InheritSubDirectories)
>        CommandLine += @" /T ";
>    if (!this.OverrideExistingRights)
>        CommandLine += @" /E ";
>
>    CommandLine += @" /P " + this.Username + ":" + this.UserRights;
>
>    //System.Windows.Forms.Clipboard.SetDataObject( CommandLine );
>
>    Process p = new Process();
>    p.StartInfo.FileName = "cacls.exe";
>    p.StartInfo.Arguments = CommandLine;
>    p.StartInfo.RedirectStandardOutput = true;
>    p.StartInfo.RedirectStandardInput = true;
>    p.StartInfo.UseShellExecute = false;
>    p.StartInfo.WindowStyle = ProcessWindowStyle.Minimized;
>    p.StartInfo.CreateNoWindow = true;
>
>
>    p.Start();
>
>    p.StandardInput.Write("Y\r\n");
>    string Response = p.StandardOutput.ReadToEnd();
>
>    // *** If no output gets generated there's an error
>    if (Response == null || Response == "")
>    {
>        this.ErrorMessage += "Unable to set permissions on " + this.Pathname + " for " + this.Username;
>        return false;
>    }
>
>    //System.Windows.Forms.MessageBox.Show( Response);
>
>    return true;
>}
>
>
>Note that you can write to StandardInput as well to bypass prompts.
>
>The other alternative is to use unsafe code to call ShellExecute or CreateProcess() to directly run the file and dump the output to file...

Thanks for the input

So, if I understand correctly, even if when I execute it from a CMD window and that I am unable to get the result in a redirected file, because of the way the Java application has been done to show its status in the CMD window, with your approach, it could still be possible to collect that information. Is that correct?
Michel Fournier
Level Extreme Inc.
Designer, architect, owner of the Level Extreme Platform
Subscribe to the site at https://www.levelextreme.com/Home/DataEntry?Activator=55&NoStore=303
Subscription benefits https://www.levelextreme.com/Home/ViewPage?Activator=7&ID=52
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform