|
? operator its like a IF-result statement.
look:
int x = 0;
int y = 1;
if(x > y) ? y++ : y--;
If x>y = true, y++.
If x>y = false, y--;
|
|
|
|
|
I am using FFMPEG for streaming operations.
(https://www.transferbigfiles.com/a3209f95-ffcc-4c82-b722-041a24c26ec1?rid=KsWHbP3Lo/rxGH4YHVVVtA%3d%3d)
I started it using the following program
Process myProcess = new Process();
myProcess.StartInfo.FileName = @"ffmpeg.exe";
myProcess.StartInfo.UseShellExecute = false;
myProcess.StartInfo.RedirectStandardInput = true;
myProcess.StartInfo.Arguments = "-i input.avi -vcodec copy -acodec copy output.avi";
myProcess.Start();
StreamWriter myStreamWriter = myProcess.StandardInput;
myStreamWriter.Write("113");
myStreamWriter.Flush();
myStreamWriter.Write('q');
myStreamWriter.Flush();
myStreamWriter.Close();
myProcess.WaitForExit();
myProcess.Close();
My intention is to close the program when I send "q" from the program (I meant a graceful exit without making any error).
But I can't close it by sending 'q' character or its corresponding ascii. When I run the program from the command line and I press q in the keyboard, program immediately gets closed.
Can you pls. help me?
Thank you
regards
anvesh
|
|
|
|
|
|
Thanx for the reply,
Its actually a nice article. But I couldn't solve my issue using it.
A carriage return is not necessary for this application to close. Pressing a 'q' itself (from keyboard) will give give graceful end to the program. I need not press an additional enter key.
And as an additional step of precaution, I made my own console program which requries a 'q' followed by carriage return to close the application, and it worked fine when I use WriteLine from .NET
What might be the issue? Its only for ffmpeg that I can't send input stream to. I am anxious to know what might be the issue?
|
|
|
|
|
I don't know, I'm stumped. But maybe the program reads something internal instead of the input stream.
What is ffmpeg? Maybe I can try it.
|
|
|
|
|
ffmpeg produces libraries and programs for handling multimedia. We can convert media files into different formats using ffmpeg. It can also record live streams from a camera in different formats.
I am attaching the ffmpeg.exe here.
https://www.transferbigfiles.com/a3209f95-ffcc-4c82-b722-041a24c26ec1?rid=KsWHbP3Lo/rxGH4YHVVVtA%3d%3d[^]
Here in my code i just copy the audio and video codecs of a file (input.avi) into another file(output.avi). Different parameters can be added in this command, but I just consider the basic operation here.
Process myProcess = new Process();
myProcess.StartInfo.FileName = @"ffmpeg.exe";
myProcess.StartInfo.UseShellExecute = false;
myProcess.StartInfo.RedirectStandardInput = true;
myProcess.StartInfo.Arguments = "-i input.avi -vcodec flv -acodec copy output.flv";
myProcess.Start();
StreamWriter myStreamWriter = myProcess.StandardInput;
myStreamWriter.Write("113");
myStreamWriter.Flush();
myStreamWriter.Write('q');
myStreamWriter.Flush();
myStreamWriter.Close();
myProcess.WaitForExit();
myProcess.Close()
;
If i run the pgm ( ffmpeg.exe should be placed in same foldr) it starts the conversion from avi to flv.
When I press [q] the pgm gets closed gracefully.
But I I am not being able to close it by sending 'q' character or its corresponding ascii.
|
|
|
|
|
anveshvm wrote: WriteLine
Oh, yeah, that may actually send a LINEFEED and a CARRIAGE-RETURN. If so, you would have to set the NewLine property.
|
|
|
|
|
Come to think of it, you may only need to add a CARRIAGE-RETURN character.
|
|
|
|
|
I have a data structure like this:
* country_name
* country_flag (image)
* country_iso_code
* country_weather_code
* country_news_code
I was thinking tosave as XML and deploy with my application but now I want to put in a resource DLL?
is it possible to put such data in resource DLL? how? any sample please?
|
|
|
|
|
Set the build action to Embeded Resource for the xml file. Then you can access the file from within the assembly using:
GetType().Assembly.GetManifestResourceStream
|
|
|
|
|
but will be built separately as DLL? I don't want to embed into my EXE and I also don't want it to be an XML type accessible for anyone via notepad!
|
|
|
|
|
Hi,
I am having problem in displaying report in doc file. the code is
SqlConnection cnx = new SqlConnection(categories.strCnx);
cnx.Open();
string query = @"select * from categories";
SqlCommand cmd = cnx.CreateCommand();
cmd.CommandText = query;
SqlDataReader dr;
HttpContext.Current.Response.Clear(); //clear anything in io buffer
HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment;filename=categories.doc");
HttpContext.Current.Response.Charset = "";
HttpContext.Current.Response.ContentType = "application/vnd.ms-document";
HttpContext.Current.Response.Write("categories" + '\n');
try
{
i = 0;
dr = cmd.ExecuteReader();
while (dr.Read())
{
s[i]= dr[0].tostring();
i++;
}
for (int j = 0; j<i; j++)
="" {
="" httpcontext.current.response.write(s[j].tostring()="" +="" '\n');
="" }
=""
="" httpcontext.current.response.end();
="" catch(exception="" ex)
="" string="" pt="ex.ToString();
" }
in="" this="" code,="" if="" i="" write="" the="" file="" inside="" while(dr.read()),="" it="" works="" fine="" but="" when="" tried="" to="" for="" loop,="" doesn't="" give="" output.=""
why="" is="" that="" and="" how="" solve="" ??="" any="" idea="" ??
<div="" class="signature">sm
|
|
|
|
|
The following two lines show a fundamental misunderstanding of type:
s[i] = dr[0].ToString();
...
s[j].ToString();
However, the problem you want addressed can be fixed by:
HttpContext.Current.Response.Flush();
HttpContext.Current.Response.Close();
instead of calling end.
|
|
|
|
|
Thanks for the reply but even the following changes did the same output.
HttpContext.Current.Response.Flush();
HttpContext.Current.Response.Close();
suchita
|
|
|
|
|
Please edit your question, and use the "Code block" widget to preserve the formatting. In addition, tick the checkbox marked 'Encode "<" (and other HTML) characters when pasting' and re paste your sample code. At present, your code cannot be fully read as the HTML is swallowing the for loop condition!
Did you know:
That by counting the rings on a tree trunk, you can tell how many other trees it has slept with.
|
|
|
|
|
Hi,
I am having problem in displaying report in doc file. the code is
SqlConnection cnx = new SqlConnection(categories.strCnx);
cnx.Open();
string query = @"select * from categories";
SqlCommand cmd = cnx.CreateCommand();
cmd.CommandText = query;
SqlDataReader dr;
HttpContext.Current.Response.Clear();
HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment;filename=categories.doc");
HttpContext.Current.Response.Charset = "";
HttpContext.Current.Response.ContentType = "application/vnd.ms-document";
HttpContext.Current.Response.Write("categories" + '\n');
try
{
i = 0;
dr = cmd.ExecuteReader();
while (dr.Read())
{
s[i]= dr[0].tostring();
i++;
}
for (int j = 0;j < i;j++)
{
HttpContext.Current.Response.Write(s[j].ToString() + '\n');
}
HttpContext.Current.Response.End();
}
catch(Exception ex)
{
string pt = ex.ToString();
}
In this code, if I write the file inside the while(dr.read()), it works fine but when i tried to write it inside the for loop, it doesn't give the output.
Why is that and how to solve it ?? Any idea ??
suchita
|
|
|
|
|
No, not quite.
Place the "code block" around your code, not your existing message. It does this:
while (dr.Read())
{
s[i]= dr[0].tostring();
i++;
}
And use the "Encode" option so that the HTML doesn't swallow < and > characters!
for (int j = 0; j Is not as helpful as
for (int j = 0; j < i - 17; j+= 123) Use the preview button to see what is happening.
Did you know:
That by counting the rings on a tree trunk, you can tell how many other trees it has slept with.
|
|
|
|
|
Thank you. I never used code block before. anyway it makes easy to read the code.
SqlConnection cnx = new SqlConnection(categories.strCnx);
cnx.Open();
string query = @"select * from categories";
SqlCommand cmd = cnx.CreateCommand();
cmd.CommandText = query;
SqlDataReader dr;
HttpContext.Current.Response.Clear();
HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment;filename=categories.doc");
HttpContext.Current.Response.Charset = "";
HttpContext.Current.Response.ContentType = "application/vnd.ms-document";
HttpContext.Current.Response.Write("categories" + '\n');
try
{
i = 0;
dr = cmd.ExecuteReader();
while (dr.Read())
{
s[i]= dr[0].tostring();
i++;
}
for (int j = 0;j<i;j++)
{
HttpContext.Current.Response.Write(s[j].ToString() + '\n');
}
HttpContext.Current.Response.End();
}
catch(Exception ex)
{
string pt = ex.ToString();
}
Thanks
suchita
|
|
|
|
|
Firstly, change your code so it compiles - dr[0].tostring() won't - it needs to be ToString().
Then I suspect it fails and throws an exception for some reason. Start by putting a breakpoint on both the
dr = cmd.ExecuteReader(); and
string pt = ex.ToString(); lines. Run your program. when you hit the first breakpoint, single step the code through - I suspect that at least one of the dr.Read elements is throwing an exception.
Did you know:
That by counting the rings on a tree trunk, you can tell how many other trees it has slept with.
|
|
|
|
|
protected void filetesting()
{
SqlConnection cnx = new SqlConnection(categories.strCnx);
cnx.Open();
string query = @"select * from categories";
SqlCommand cmd = cnx.CreateCommand();
cmd.CommandText = query;
SqlDataReader dr;
HttpContext.Current.Response.Clear();
HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment;filename=categories.doc");
HttpContext.Current.Response.Charset = "";
HttpContext.Current.Response.ContentType = "application/vnd.ms-document";
HttpContext.Current.Response.Write("categories" + '\n');
try
{
i = 0;
dr = cmd.ExecuteReader();
while (dr.Read())
{
HttpContext.Current.Response.Write( dr[0].ToString());
i++;
}
for (int j = 0; j < i; j++)
{
temp += s[j]+ '\n';
}
HttpContext.Current.Response.End();
}
catch(Exception ex)
{
string pt = ex.ToString();
}
}
This works fine when i put the "HttpContext.Current.Response.End()" before the for loop but I want to run it after for loop. I want to execute "HttpContext.Current.Response.Write" command inside the for loop. But since it wasn't running, I kept it inside the while(dr.read()) code. But i really want to have "HttpContext.Current.Response.Write" inside the for loop.
suchita
|
|
|
|
|
OK, this won't fix your problem (though it may appear to in a way). Alter your try block to include a finally block as well, and move the Response.End to there:
try
{
i = 0;
dr = cmd.ExecuteReader();
while (dr.Read())
{
HttpContext.Current.Response.Write( dr[0].ToString());
i++;
}
for (int j = 0; j < i; j++)
{
temp += s[j]+ '\n';
}
}
catch(Exception ex)
{
string pt = ex.ToString();
}
finally
{
HttpContext.Current.Response.End();
}
What this does is ensure that whatever you have written to the HttpContext will get written to your client, whether it fails or not.
THIS DOES NOT FIX THE PROBLEM!
You should find that some of your data is written, and some is not, which should give you a clue as to what is going wrong.
Did you know:
That by counting the rings on a tree trunk, you can tell how many other trees it has slept with.
|
|
|
|
|
When i try to store the datareader value in string array and using that string array to write in a file, it gave the same problem ?? Code is like below ::
try
{
i = 0;
dr = cmd.ExecuteReader();
while (dr.Read())
{
s[i] = dr[0].ToString();
i++;
}
for (int j = 0; j < i; j++)
{
HttpContext.Current.Response.Write(s[j] + '\n';
}
HttpContext.Current.Response.End();
}
catch (Exception ex)
{
string pt = ex.ToString();
}
finally
{ HttpContext.Current.Response.End(); }
suchita
|
|
|
|
|
Then the problem must be the string you get back from the DataReader - which implies a problem in your DB. Try checking for nulls in your for loop:
for (int j = 0; j < i; j++)
{
if (s[j] == null)
{
HttpContext.Current.Response.Write("HELP!\n");
}
else
{
HttpContext.Current.Response.Write(s[j] + "\n");
}
} If you get "HELP!" in your HttpContext, look at your data!
Did you know:
That by counting the rings on a tree trunk, you can tell how many other trees it has slept with.
|
|
|
|
|
the error was same as always.. no change in error.
System.NullReferenceException: Object reference not set to an instance of an object.
at catagories.Default_View.filetesting() in C:\Documents and Settings\smanandhar\My Documents\Visual Studio 2008\Projects\catagories\Default_View.ascx.cs:line 1224
Also if it was the database error, then it wouldn't be showing when i display the same data in datagrid. Well I can show them in datagrid without any error.
suchita
|
|
|
|
|
Post the actual code you are using (cut and paste rather than hand modify the existing post).
Since you say (for the first time) it is a null-reference error at line 1224 in your code: look at line 1224 in your code. I am pretty sure you will find it is the line:
HttpContext.Current.Response.Write(s[j] + "\n");
(Since there are 1224 lines, just post the single method - but make sure it comes from the VS source, and don't forget the "encode HTML" option when you paste it).
SayamiSuchi wrote: Also if it was the database error, then it wouldn't be showing when i display the same data in datagrid. Well I can show them in datagrid without any error.
What on earth makes you believe that?
All that means is that the datagrid takes care to check for null entries and display them as blank!
Did you know:
That by counting the rings on a tree trunk, you can tell how many other trees it has slept with.
|
|
|
|