Allegro.cc - Online Community

Allegro.cc Forums » Off-Topic Ordeals » [C#/.NET] Starting Another Process And Writing To StandardInput (stdin)

This thread is locked; no one can reply to it. rss feed Print
 1   2 
[C#/.NET] Starting Another Process And Writing To StandardInput (stdin)
bamccaig
Member #7,536
July 2006
avatar

BAF said:

Personally, I would check out a working copy, use htaccess do deny any access to anything .svn, and then just issue a svn update.

You're assuming the Web server is Apache. :)

CGamesPlay said:

You used --config-dir and --non-interactive? You should run it manually and add in the user and password information, since it seems it couldn't ask you for them.

Yes, both options were used. The user authentication information should already be cached... :-/ A colleague with server access can run svn export with the --config-dir option and it executes successfully without any prompts... :-/

** EDIT **

Executing the exact same svn export command as the batch file (with the --non-interactive option)(and to be paranoid, my colleague's personal "%APPDATA%\Subversion" directory deleted), she is getting the same stderr output as the hook script.

** EDIT **

Without the --non-interactive option apparently it just sits there... :-/

svn export --force --config-dir "directory" "file_url" "file_path" \ 1>"svn-stdout.txt" 2>"svn-stderr.txt"

** EDIT **

As an administrator, it executes fine. :-/

** EDIT **

Actually, svn wasn't just sitting there... It was waiting for her to enter the password. The username/password prompt was being redirected to files... :-[

CGamesPlay said:

You should run it manually and add in the user and password information, since it seems it couldn't ask you for them.

You appear to be correct... I thought we already saved the user credentials, but apparently not... So we're doing it again now... I'm about to find out if it worked...

** EDIT **

Now the hook script fails and none of the stream files exist. :-/

BAF
Member #2,981
December 2002
avatar

Run it as the user it will be run as manually, without the redirection.

bamccaig
Member #7,536
July 2006
avatar

BAF said:

Run it as the user it will be run as manually, without the redirection.

I don't even know if that's possible... The user has no logon, whatever that means... :-/

Anyway, it seems that when I sent the latest revision of my program to replace the currently "installed" one I sent it with a .txt extension appended. My colleague forgot to rename it so the batch file wasn't able to find my program, which caused it to fail and no output to be captured... After correcting that, I got log messages indicating that svn exited with a non-zero exit status. When I left work I had just modified the program to capture svn's output. Tomorrow I'll see if that yields anything useful. :-/

BAF
Member #2,981
December 2002
avatar

You can still run it as that user.

CGamesPlay
Member #2,559
July 2002
avatar

Just so we're clear, the only purpose of the C# program is to run svn export? And you are running the C# program from a batch file? If that is actually the case, then what you are doing is almost worse-than-failure-worthy.

On the topic of actually making the solution work: if it's asking for a user name and password, provide one. The commands are quite clearly shown in svn help export.

--
Tomasu: Every time you read this: hugging!

Ryan Patterson - <http://cgamesplay.com/>

bamccaig
Member #7,536
July 2006
avatar

BAF said:

You can still run it as that user.

IIRC, I asked my colleague to do that and either it failed because "the user account doesn't have a logon" or my colleague didn't know how to do it (or I misinterpreted her)... :-/

CGamesPlay said:

Just so we're clear, the only purpose of the C# program is to run svn export? And you are running the C# program from a batch file? If that is actually the case, then what you are doing is almost worse-than-failure-worthy.

The C# program only exports files that have changed in the most recent commit (as well as creating directories and deleting files/directories) as indicated by svnlook changed. There are thousands files which as you can expect would take a long time to export each time. Obviously svn update would be a nice, simple solution, but then you have the .svn directories which are undesired, especially on remote, third party servers. There may be better ways to do what I'm doing, but this is the solution I've come up with... :-/

BAF
Member #2,981
December 2002
avatar

Just hide the .svn directories. Can't be that hard, no matter what you're using.

bamccaig
Member #7,536
July 2006
avatar

BAF said:

Just hide the .svn directories. Can't be that hard, no matter what you're using.

I tried to Google it and came up mostly empty... :-/ Anybody know how to configure IIS to NOT serve directories based on name alone? I don't know if the higher ups would go for this anyway so it's only a partial/alternative solution. I've still gotta get my program to interface properly with Subversion.

CGamesPlay
Member #2,559
July 2002
avatar

How about just do an svn update locally and then copy all the files that aren't named ".svn"?

--
Tomasu: Every time you read this: hugging!

Ryan Patterson - <http://cgamesplay.com/>

bamccaig
Member #7,536
July 2006
avatar

CGamesPlay said:

How about just do an svn update locally and then copy all the files that aren't named ".svn"?

We'd rather an automated process... It should be more reliable and less error-prone (I hope).

** EDIT **

The output from svn, when executed by my program/hook script, is...

svn: PROPFIND request failed on 'relative_file_path' svn: PROPFIND of 'relative_file_path': authorization failed (url)

My colleague can run the same command fine without any prompts or errors. WTF!? >:(:'(

CGamesPlay
Member #2,559
July 2002
avatar

Quote:

We'd rather an automated process... It should be more reliable and less error-prone (I hope).

It's pretty easy: you already have this:

Quote:

The C# program only exports files that have changed in the most recent commit (as well as creating directories and deleting files/directories) as indicated by svnlook changed.

So just takes those files, and copy them using the C# program, instead of using svn export. Maybe a mapped network drive, maybe FTP, maybe WebDAV, whatever you like.

--
Tomasu: Every time you read this: hugging!

Ryan Patterson - <http://cgamesplay.com/>

bamccaig
Member #7,536
July 2006
avatar

CGamesPlay said:

So just takes those files, and copy them using the C# program, instead of using svn export. Maybe a mapped network drive, maybe FTP, maybe WebDAV, whatever you like.

Copy them from where? :-/ They're in a Subversion repository until they get exported out... I'm not sure I understand what you're suggesting. If my colleague manually executes the hook script with the same arguments that Subversion passes it, it works flawlessly. It seems the only problem is with user permissions on the server. :-/

CGamesPlay
Member #2,559
July 2002
avatar

Maybe you think that svn export can store the files on a remote destination? It can't.

I'm going to start from scratch. You have a subversion repository and a web server. These are on different machines. You need the web server to be updated when the subversion repository is updated.

I would solve this problem using a post-commit hook, like you are trying to do. The post commit hook obviously runs on the machine with the subversion repository.

The script should maintain a local copy of the repository (updated with svn update). When the script is executed, it should update the repository, then copy all of the files in the local repository to the remote server, ignoring the subversion special directories.

As an example, this would be the script, using lftp to send the files over unencrypted FTP.

cd C:\subversion\www_files
svn up
lftp ftp://user:password@host -e "mirror -nvR --delete -x \.svn . ."

This is based on a script I use to update a static HTML web site that uses a subversion repository to maintain its files. The script only updates files that have changed, as based on the time stamp and file size. The update process is slow if there are a large number of directories in the repository (lftp must look in each one on the remote server).

--
Tomasu: Every time you read this: hugging!

Ryan Patterson - <http://cgamesplay.com/>

BAF
Member #2,981
December 2002
avatar

If you can access the files locally (mapped network drive or something), instead of using FTP, you could use rsync, might be faster...

bamccaig
Member #7,536
July 2006
avatar

Well the server is running Windows Server and the Subversion server and Web server are both running on the same machine with "local access" to the repositories and document roots. I need a Windows solution and I'm pretty sure I was told that Cygwin-/MSYS-like tools are not an option. :-/

CGamesPlay
Member #2,559
July 2002
avatar

Have you tried using svn export using the local paths then? Obviously this isn't the solution you should use in the long-term, but does it work?

If you have access to the wwwroot locally, you can replace lftp with xcopy. It's seriously the easiest thing ever, after I just tried it.

xcopy can recursively (/E) copy a directory and by default ignores hidden files (.svn directories are hidden). xcopy can also be made to only copy files with the archive bit set (/M; the archive bit is set by writing to the file). It can be forced with /Y. xcopy also has a decent file exclusion pattern, but it won't be needed if all you want to do is ignore the hidden files and directories. So, the solution:

REM assumes that a checked out repository is in C:\inetpub\trunk
REM and that the webroot is C:\inetpub\wwwroot
cd C:\inetpub
svn up trunk
xcopy /M /E /Y trunk wwwroot

By using /M, xcopy will copy all files that have been written, then clear the archive bit, so only changed files will be written after that point. Note that this will not handle deletion of files.

--
Tomasu: Every time you read this: hugging!

Ryan Patterson - <http://cgamesplay.com/>

bamccaig
Member #7,536
July 2006
avatar

CGamesPlay said:

Have you tried using svn export using the local paths then? Obviously this isn't the solution you should use in the long-term, but does it work?

No, I hadn't. :-[ It works fine with a file:/// url. Why isn't this a solution to use in the long-term though? :-/ Am I missing something?

CGamesPlay
Member #2,559
July 2002
avatar

If you are using subversion export with an https repository URL and a local path for the local url, then you should be fine. I think the svn up idea is a better solution though.

--
Tomasu: Every time you read this: hugging!

Ryan Patterson - <http://cgamesplay.com/>

bamccaig
Member #7,536
July 2006
avatar

Currently, I'm using subversion export with a file repository URL (file:///) and a local path (<tt><DriveLetter>:</tt>). Is there anything particularly wrong with it (i.e. security holes or performance)? :-/

The svn up idea does sound better, but it would still need a wrapper of some sort to send particular branches to particular web roots (i.e. current development branch, current testing branch) automatically when they are committed. As is, a simple configuration file is used that matches branches to web roots... :-/ That was pretty much why I moved it into a C# program. :-/

CGamesPlay
Member #2,559
July 2002
avatar

Quote:

Is there anything particularly wrong with it (i.e. security holes or performance)? :-/

I'm going to go with file locking issues because you are having two processes access the database at the same time. It is probably fine, but personally I'd prefer to use the web URL if it were possible.

Quote:

As is, a simple configuration file is used that matches branches to web roots... :-/ That was pretty much why I moved it into a C# program. :-/

Yeah, I figured that was what was going on, but you were being pretty vague :)

--
Tomasu: Every time you read this: hugging!

Ryan Patterson - <http://cgamesplay.com/>

Crazy Photon
Member #2,588
July 2002
avatar

Have you tried saving the users in a file and then redirect stdin to the execution command?

svn .... < bleh.txt

-----
Resistance is NEVER futile...

bamccaig
Member #7,536
July 2006
avatar

Crazy Photon said:

Have you tried saving the users in a file and then redirect stdin to the execution command?

svn .... < bleh.txt

I think we've already solved the problem you're offering solutions for. :-/ Thanks though. :) Currently, the only problem appears the be the inability to use an https:// url for the repository. It seems to work with a file:/// url, but for various reasons I'd prefer to get https:// working. :-/ I assume the reason https:// doesn't work is because the user account running the Subversion server (which executes the hook script) has limited permissions, but I don't know much about Windows Server, its user accounts, or the actual user's configuration. :-/

aj5555
Member #9,033
September 2007

i do this process/stdin stuff all the time with just plain C.

 1   2 


Go to: