Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I'm trying to run an external problem from C# by using Process.Start, but am running into permissions issues. When I open a command prompt normally (not as an admin) and run my commands they work fine, but when I open a command prompt via Process.Start, I get a write error on the directory. ("I can't write on file test.log")
If I run it as an admin via Process.Start it works fine, but I get the permissions popup. Does anyone have any ideas that might help me figure this out? Thanks!

Here is the code I'm using:

Process proc = new Process();
proc.StartInfo.FileName = @"cmd.exe";
proc.StartInfo.Arguments = @"/k latex C:UsersShaneDocumentsest.tex";
proc.Start();
proc.WaitForExit();
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
169 views
Welcome To Ask or Share your Answers For Others

1 Answer

I wonder whether it's trying to write a diagnostic log to the current working directory, which you may not have permissions for. (I don't know offhand whether it will inherit the working directory, or be the directory that contains cmd.exe.) I suggest you specify the working directory for the new process using ProcessStartInfo.WorkingDirectory.

(As an aside, I personally find it cleaner to create a new ProcessStartInfo an populate that - C# object initializers make this particularly nice) and then call Process.Start(ProcessStartInfo) to start it. Otherwise it looks like there's already a process when there isn't really one yet. Just MHO though, and unrelated to the problem you're investigating, probably.)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share

548k questions

547k answers

4 comments

86.3k users

...