Menu

External process can not write to filesystem?

Anonymous
2021-04-27
2021-04-29
  • Anonymous

    Anonymous - 2021-04-27

    Hi,
    I'm having difficulties with external program execution (with createProcess or createProcessAsynchronous) which returns "Access denied" when trying to write to textfile.

    Take for example simple test.cmd file which only has ECHO Hello >> test.txt in it and try running it directly or run it from script with createProcessAsynchronous().

    Seems like process does not have permissions to write to filesystem - is there a way to adjust it somehow?

    Martin

     
  • Stefan Zieker

    Stefan Zieker - 2021-04-27

    Hi Martin,

    if you want to execute a cmd file you have to start cmd.exe with createProcess or createProcessAsynchronous and pass your cmd file as argument.

    I think you have to pass following arguments for a script on d:/:
    /C D:/simple.cmd

    Stefan

     

    Last edit: Stefan Zieker 2021-04-28
  • Stefan Zieker

    Stefan Zieker - 2021-04-28

    Hi Martin,

    I tested it on Windows 10 and it worked. Did you set the correct working path? If not the working path is the ScriptCommunicator folder. Below is my test code (the file is created in the script folder):

    var arguments = Array("/C,", scriptFile.getScriptFolder() + "/test.cmd");
    var executable = "cmd.exe";
    
    scriptThread.createProcessAsynchronous(executable, arguments, 3000, scriptThread.getScriptFolder());
    

    Stefan

     
  • Anonymous

    Anonymous - 2021-04-28

    Hi Stefan,

    working path was the exact problem. I had an answer prepared already, but I rather made some more testing before posting it. I had difficulties with that approach, but your last post could clear that part, so I deleted it and here is the rest:

    Turns out I did not correctly set workingDirectory argument for createProcessAsynchronous() function so the external program was starting in ScriptCommunicator folder in Program Files, which requires elevated rights to modify files in it (Win10 btw). As an example this seems to work correctly: var process = scriptThread.createProcessAsynchronous("C:/path with spaces/test.cmd", Array(""), 30000, "C:/path with spaces/");

    I'm actually creating a simple programming app which uses external programming tool, so I have to start it with some additional arguments which can be adjusted in settings tab of the app, and also check the exitCode of the external tool to see the programming result. This way I can actually read not only exit codes but also standard output and error output of the tool, so I can then display the error message directly. Very nice :)

    One last thing would be to change cursor to hourglass or indicate in another way that external tool is working, is there some simple way, most likely with conjunction of waitForFinishedProcess() function?

     
  • Stefan Zieker

    Stefan Zieker - 2021-04-29

    Hi Martin,

    you can add a progress bar to your gui (min. value 0, max. 100). Then create a timer and increase the value of the progress bar every 500ms by X. If you reach 100 start over at 0.

    Stefan

     

    Last edit: Stefan Zieker 2021-04-29
  • Anonymous

    Anonymous - 2021-04-29

    That would work, thank you Stefan!

    Martin

     

Anonymous
Anonymous

Add attachments
Cancel





Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.